Class: Gempilot::VersionTag

Inherits:
Object
  • Object
show all
Includes:
StrictShell
Defined in:
lib/gempilot/version_tag.rb

Overview

Manages git operations for version releases.

Constant Summary collapse

BUMP_MESSAGE_PREFIX =

Commit-message prefix written for a version bump; the guard below matches on it, so the two must stay in sync.

"Bump version to ".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ VersionTag

Returns a new instance of VersionTag.



14
15
16
# File 'lib/gempilot/version_tag.rb', line 14

def initialize(version)
  @version = version
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



12
13
14
# File 'lib/gempilot/version_tag.rb', line 12

def version
  @version
end

Instance Method Details

#createObject



18
19
20
21
22
23
24
# File 'lib/gempilot/version_tag.rb', line 18

def create
  _, _, status = Open3.capture3("git", "diff", "--staged", "--quiet")
  raise "Cannot proceed, staging area must be clean" unless status.success?

  sh "git", "add", version.path.to_s
  sh "git", "commit", "-m", "#{BUMP_MESSAGE_PREFIX}#{version.value}"
end

#resetObject



36
37
38
39
40
# File 'lib/gempilot/version_tag.rb', line 36

def reset
  assert_last_commit_is_bump!
  sh "git", "reset", "--quiet", "--mixed", "HEAD~1"
  sh "git", "restore", version.path.to_s
end

#revertObject



42
43
44
45
# File 'lib/gempilot/version_tag.rb', line 42

def revert
  assert_last_commit_is_bump!
  sh "git", "revert", "HEAD", "--no-edit"
end

#tagObject



26
27
28
29
# File 'lib/gempilot/version_tag.rb', line 26

def tag
  assert_last_commit_is_bump!
  sh "git", "tag", version.tag
end

#untagObject



31
32
33
34
# File 'lib/gempilot/version_tag.rb', line 31

def untag
  assert_last_commit_is_bump!
  sh "git", "tag", "--delete", version.tag
end