Class: RakeCommit::Git
- Inherits:
-
Object
- Object
- RakeCommit::Git
- Defined in:
- lib/rake_commit/git.rb
Instance Method Summary collapse
- #add ⇒ Object
- #collapse_git_commits ⇒ Object
- #collapse_git_commits? ⇒ Boolean
- #commit ⇒ Object
- #git_branch ⇒ Object
- #incremental_commit ⇒ Object
-
#initialize(build_command, collapse_commits = true, rebase_only = false, incremental = false, prompt_exclusions = [], precommit = nil, commit_message_wrap = nil, commit_message_type = MessageType::MESSAGE) ⇒ Git
constructor
A new instance of Git.
- #merge_base ⇒ Object
- #merge_commits? ⇒ Boolean
- #nothing_to_commit? ⇒ Boolean
- #pull_rebase ⇒ Object
- #push ⇒ Object
- #rebase_continue ⇒ Object
- #rebase_in_progress? ⇒ Boolean
- #rebase_only? ⇒ Boolean
- #reset_soft ⇒ Object
- #status ⇒ Object
- #temp_commit ⇒ Object
Constructor Details
#initialize(build_command, collapse_commits = true, rebase_only = false, incremental = false, prompt_exclusions = [], precommit = nil, commit_message_wrap = nil, commit_message_type = MessageType::MESSAGE) ⇒ Git
Returns a new instance of Git.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rake_commit/git.rb', line 6 def initialize(build_command, collapse_commits = true, rebase_only = false, incremental = false, prompt_exclusions = [], precommit = nil, = nil, = MessageType::MESSAGE) @build_command = build_command @collapse_commits = collapse_commits @rebase_only = rebase_only @incremental = incremental @prompt_exclusions = prompt_exclusions @precommit = precommit @commit_message_wrap = @commit_message_type = end |
Instance Method Details
#add ⇒ Object
75 76 77 |
# File 'lib/rake_commit/git.rb', line 75 def add RakeCommit::Shell.system "git add -A ." end |
#collapse_git_commits ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rake_commit/git.rb', line 59 def collapse_git_commits RakeCommit::Shell.system(@precommit) unless @precommit.nil? add temp_commit reset_soft status return if nothing_to_commit? incremental_commit pull_rebase rescue return false return true end |
#collapse_git_commits? ⇒ Boolean
43 44 45 46 47 48 49 |
# File 'lib/rake_commit/git.rb', line 43 def collapse_git_commits? return false unless @collapse_commits return true unless merge_commits? status input = Readline.readline("Do you want to collapse merge commits? (y/n): ").chomp input == "y" end |
#commit ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rake_commit/git.rb', line 17 def commit if @incremental incremental_commit elsif rebase_in_progress? rebase_continue RakeCommit::Shell.system(@build_command) push else if collapse_git_commits? return unless collapse_git_commits elsif rebase_only? unless nothing_to_commit? puts "You have uncommitted changes. Please amend, stash, or clean and retry." exit 1 end pull_rebase rescue return false end RakeCommit::Shell.system(@build_command) push end end |
#git_branch ⇒ Object
111 112 113 114 115 116 |
# File 'lib/rake_commit/git.rb', line 111 def git_branch @git_branch ||= begin output = RakeCommit::Shell.backtick("git symbolic-ref HEAD") output.gsub('refs/heads/', '').strip end end |
#incremental_commit ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/rake_commit/git.rb', line 79 def incremental_commit = RakeCommit::CommitMessage.new(@prompt_exclusions, @commit_message_type) unless ..nil? RakeCommit::Shell.system("git config user.name #{Shellwords.shellescape(.)}") end = .(@commit_message_wrap) RakeCommit::Shell.system("git commit -m #{Shellwords.shellescape()}") end |
#merge_base ⇒ Object
122 123 124 |
# File 'lib/rake_commit/git.rb', line 122 def merge_base @merge_base ||= RakeCommit::Shell.backtick("git merge-base #{git_branch} origin/#{git_branch}").strip end |
#merge_commits? ⇒ Boolean
118 119 120 |
# File 'lib/rake_commit/git.rb', line 118 def merge_commits? RakeCommit::Shell.backtick("git log #{merge_base}..HEAD") != RakeCommit::Shell.backtick("git log --no-merges #{merge_base}..HEAD") end |
#nothing_to_commit? ⇒ Boolean
106 107 108 109 |
# File 'lib/rake_commit/git.rb', line 106 def nothing_to_commit? status = RakeCommit::Shell.backtick("git status", false) status.empty? || status =~ /nothing to commit/m end |
#pull_rebase ⇒ Object
93 94 95 |
# File 'lib/rake_commit/git.rb', line 93 def pull_rebase RakeCommit::Shell.system "git pull --rebase --stat" end |
#push ⇒ Object
97 98 99 |
# File 'lib/rake_commit/git.rb', line 97 def push RakeCommit::Shell.system "git push origin #{git_branch}" end |
#rebase_continue ⇒ Object
55 56 57 |
# File 'lib/rake_commit/git.rb', line 55 def rebase_continue RakeCommit::Shell.system("git rebase --continue") end |
#rebase_in_progress? ⇒ Boolean
39 40 41 |
# File 'lib/rake_commit/git.rb', line 39 def rebase_in_progress? File.directory?(".git/rebase-merge") || File.directory?(".git/rebase-apply") end |
#rebase_only? ⇒ Boolean
51 52 53 |
# File 'lib/rake_commit/git.rb', line 51 def rebase_only? !!@rebase_only end |
#reset_soft ⇒ Object
88 89 90 91 |
# File 'lib/rake_commit/git.rb', line 88 def reset_soft raise "Could not determine branch" unless git_branch RakeCommit::Shell.system "git reset --soft #{merge_base}" end |
#status ⇒ Object
71 72 73 |
# File 'lib/rake_commit/git.rb', line 71 def status RakeCommit::Shell.system("git status", false) end |
#temp_commit ⇒ Object
101 102 103 104 |
# File 'lib/rake_commit/git.rb', line 101 def temp_commit return if nothing_to_commit? RakeCommit::Shell.system "git commit -m 'rake_commit backup commit'" end |