Class: CaptiveRelease::GitCommands
- Inherits:
-
Object
- Object
- CaptiveRelease::GitCommands
- Defined in:
- lib/captive_release/git_commands.rb
Class Method Summary collapse
- .add_and_commit(version, paths) ⇒ Object
- .commits_since(tag) ⇒ Object
- .dirty? ⇒ Boolean
- .last_tag ⇒ Object
- .push(version) ⇒ Object
- .remote_url ⇒ Object
- .run!(cmd) ⇒ Object
- .tag(version) ⇒ Object
Class Method Details
.add_and_commit(version, paths) ⇒ Object
24 25 26 27 |
# File 'lib/captive_release/git_commands.rb', line 24 def self.add_and_commit(version, paths) run! "git add #{paths.map { |p| shellescape(p) }.join(" ")}" run! %(git commit -m "🔖 Set version v#{version}") end |
.commits_since(tag) ⇒ Object
15 16 17 18 |
# File 'lib/captive_release/git_commands.rb', line 15 def self.commits_since(tag) range = tag ? "#{tag}..HEAD" : "HEAD" `git log #{range} --pretty=format:"- %s (%h)" --no-merges`.strip end |
.dirty? ⇒ Boolean
5 6 7 8 |
# File 'lib/captive_release/git_commands.rb', line 5 def self.dirty? lines = `git diff --name-only && git diff --cached --name-only`.lines.map(&:strip).reject(&:empty?) !lines.empty? end |
.last_tag ⇒ Object
10 11 12 13 |
# File 'lib/captive_release/git_commands.rb', line 10 def self.last_tag tag = `git describe --tags --abbrev=0 2>/dev/null`.strip tag.empty? ? nil : tag end |
.push(version) ⇒ Object
33 34 35 36 |
# File 'lib/captive_release/git_commands.rb', line 33 def self.push(version) run! "git push origin HEAD" run! "git push origin v#{version}" end |
.remote_url ⇒ Object
20 21 22 |
# File 'lib/captive_release/git_commands.rb', line 20 def self.remote_url `git remote get-url origin 2>/dev/null`.strip end |
.run!(cmd) ⇒ Object
38 39 40 |
# File 'lib/captive_release/git_commands.rb', line 38 def self.run!(cmd) system(cmd) || raise("Git command failed: #{cmd}") end |
.tag(version) ⇒ Object
29 30 31 |
# File 'lib/captive_release/git_commands.rb', line 29 def self.tag(version) run! "git tag v#{version}" end |