Skip to content

Commit 2245471

Browse files
author
Evan Phoenix
committed
Detect the proper merge location using config
1 parent eff69b6 commit 2245471

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.*.swp

enhance.rb

+11
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,16 @@ def am_info
7575
def to_be_committed
7676
@git.diff_index({:cached => true, :name_only => true}, "HEAD").split("\n")
7777
end
78+
79+
def path2ref(name)
80+
name.gsub %r!^refs/heads/!, ""
81+
end
82+
83+
def merge_ref(branch)
84+
repo = @git.config({}, "branch.#{branch}.remote").strip
85+
ref = @git.config({}, "branch.#{branch}.merge").strip
86+
path = "#{repo}/#{path2ref(ref)}"
87+
return path
88+
end
7889
end
7990
end

git-update.rb

+11-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@
3535

3636
STDOUT.sync = true
3737

38-
top = `git rev-parse --show-cdup 2>&1`.strip
38+
# cd to the top of this git tree. If run via git's alias
39+
# infrastructure, this is done for us. We do it again, just
40+
# to be sure.
3941

42+
top = `git rev-parse --show-cdup 2>&1`.strip
4043
Dir.chdir top unless top.empty?
4144

4245
repo = Grit::Repo.new(".")
@@ -48,16 +51,20 @@
4851
# TODO parse +out+ for details to show the user.
4952

5053
current = repo.resolve_rev "HEAD"
51-
origin = repo.resolve_rev "origin"
52-
5354
branch = repo.git.symbolic_ref({:q => true}, "HEAD").strip
5455

56+
branch_name = branch.gsub %r!^refs/heads/!, ""
57+
58+
origin_ref = repo.merge_ref branch_name
59+
origin = repo.resolve_rev origin_ref
60+
5561
common = repo.find_ancestor(origin, current)
5662

5763
to_replay = repo.revs_between(common, current)
5864
to_receive = repo.revs_between(common, origin)
5965

6066
if opts.analyze
67+
puts "Automatically merging in refs from: #{origin_ref} / #{origin[0,7]}"
6168
puts "Closest ancestor between HEAD and origin: #{common[0,7]}"
6269
puts
6370

@@ -68,7 +75,7 @@
6875

6976
puts "#{to_receive.size} new commits."
7077
if opts.verbose
71-
system "git log --pretty=oneline #{common}..origin"
78+
system "git log --pretty=oneline #{common}..#{origin_ref}"
7279
puts
7380
end
7481

0 commit comments

Comments
 (0)