Class: Git
- Inherits:
-
Object
- Object
- Git
- Defined in:
- lib/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(collapse_commits = true, incremental = false, prompt_exclusions = []) ⇒ Git
constructor
A new instance of Git.
- #merge_base ⇒ Object
- #merge_commits? ⇒ Boolean
- #nothing_to_commit? ⇒ Boolean
- #pull_rebase ⇒ Object
- #push ⇒ Object
- #reset_soft ⇒ Object
- #status ⇒ Object
- #temp_commit ⇒ Object
Constructor Details
#initialize(collapse_commits = true, incremental = false, prompt_exclusions = []) ⇒ Git
Returns a new instance of Git.
3 4 5 6 7 |
# File 'lib/git.rb', line 3 def initialize(collapse_commits = true, incremental = false, prompt_exclusions = []) @collapse_commits = collapse_commits @incremental = incremental @prompt_exclusions = prompt_exclusions end |
Instance Method Details
#collapse_git_commits ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/git.rb', line 26 def collapse_git_commits add temp_commit reset_soft status return if nothing_to_commit? incremental_commit pull_rebase end |
#collapse_git_commits? ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/git.rb', line 19 def collapse_git_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
9 10 11 12 13 14 15 16 17 |
# File 'lib/git.rb', line 9 def commit if @incremental incremental_commit else collapse_git_commits if @collapse_commits && collapse_git_commits? Shell.system("rake") push end end |
#git_branch ⇒ Object
76 77 78 79 80 81 |
# File 'lib/git.rb', line 76 def git_branch @git_branch ||= begin output = Shell.backtick("git symbolic-ref HEAD") output.gsub('refs/heads/', '').strip end end |
#incremental_commit ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/git.rb', line 44 def incremental_commit = CommitMessage.new(@prompt_exclusions) unless .pair.nil? Shell.system("git config user.name #{.pair.inspect}") end = [.feature, .].compact.join(" - ") Shell.system("git commit -m #{.inspect}") end |
#merge_base ⇒ Object
87 88 89 |
# File 'lib/git.rb', line 87 def merge_base @merge_base ||= Shell.backtick("git merge-base #{git_branch} origin/#{git_branch}").strip end |
#merge_commits? ⇒ Boolean
83 84 85 |
# File 'lib/git.rb', line 83 def merge_commits? Shell.backtick("git log #{merge_base}..HEAD") != Shell.backtick("git log --no-merges #{merge_base}..HEAD") end |
#nothing_to_commit? ⇒ Boolean
71 72 73 74 |
# File 'lib/git.rb', line 71 def nothing_to_commit? status = Shell.backtick("git status", false) status.empty? || status =~ /nothing to commit/m end |
#pull_rebase ⇒ Object
58 59 60 |
# File 'lib/git.rb', line 58 def pull_rebase Shell.system "git pull --rebase" end |
#push ⇒ Object
62 63 64 |
# File 'lib/git.rb', line 62 def push Shell.system "git push origin #{git_branch}" end |
#reset_soft ⇒ Object
53 54 55 56 |
# File 'lib/git.rb', line 53 def reset_soft raise "Could not determine branch" unless git_branch Shell.system "git reset --soft #{merge_base}" end |