Signed-off-by: Felipe Contreras <felipe.contre...@gmail.com>
---

Notes:
    Let's start deviating from the original script.
    
    There are no functional changes though.

 git-request-pull.rb | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/git-request-pull.rb b/git-request-pull.rb
index eee2e28..9d3e9ab 100755
--- a/git-request-pull.rb
+++ b/git-request-pull.rb
@@ -62,21 +62,20 @@ base = ARGV[0]
 url = ARGV[1]
 head = ARGV[2] || 'HEAD'
 status = 0
-branch_name = nil
+branch_name = branch_desc = nil
+
+usage unless base or url
 
 headref = `git rev-parse -q --verify --symbolic-full-name "#{head}"`.chomp
-headref = "" if headref == "HEAD"
 
-branch_name = headref.gsub(%r{^refs/heads/}, '')
-if branch_name == headref ||
-  ! system(%[git config "branch.#{branch_name}.description" >/dev/null])
-  branch_name = nil
+if headref.start_with?('refs/heads')
+  branch_name = headref[11..-1]
+  branch_desc = `git config "branch.#{branch_name}.description"`.chomp
+  branch_name = nil if branch_desc.empty?
 end
 
 tag_name = `git describe --exact "#{head}^0" 2>/dev/null`.chomp
 
-usage unless base or url
-
 baserev = `git rev-parse --verify --quiet "#{base}"^0`.chomp
 die "Not a valid revision: #{base}" if baserev.empty?
 
@@ -86,7 +85,7 @@ die "Not a valid revision: #{head}" if headrev.empty?
 merge_base = `git merge-base #{baserev} #{headrev}`.chomp
 die "No commits in common between #{base} and #{head}" unless $?.success?
 
-ref = get_ref(url, headref, headrev, tag_name) || ''
+ref = get_ref(url, headref != "HEAD" ? headref : nil, headrev, tag_name)
 url = `git ls-remote --get-url "#{url}"`.chomp
 
 begin
@@ -96,7 +95,7 @@ begin
 
 are available in the git repository at:
 ' #{merge_base}])
-  puts "  #{url}" + (ref.empty? ? "" : " #{ref}")
+  puts "  #{url}" + (ref ? " #{ref}" : "")
   run(%[git show -s --format='
 for you to fetch changes up to %H:
 
@@ -107,11 +106,11 @@ for you to fetch changes up to %H:
   if branch_name
     puts "(from the branch description for #{branch_name} local branch)"
     puts
-    run(%[git config "branch.#{branch_name}.description"])
+    puts branch_desc
   end
 
   if not tag_name.empty?
-    if ref.empty? || ref != "tags/#{tag_name}"
+    if ref != "tags/#{tag_name}"
       $stderr.puts "warn: You locally have #{tag_name} but it does not (yet)"
       $stderr.puts "warn: appear to be at #{url}"
       $stderr.puts "warn: Do you want to push it there, perhaps?"
@@ -124,14 +123,13 @@ for you to fetch changes up to %H:
     puts "----------------------------------------------------------------"
   end
 
-  run(%[git shortlog ^#{baserev} #{headrev}])
-  run(%[git diff -M --stat --summary #{patch} #{merge_base}..#{headrev}])
+  run(%[git shortlog ^#{base} #{head}])
+  run(%[git diff -M --stat --summary #{patch} ^#{merge_base} #{head}])
 
-  if ref.empty?
-    short_headref = `git rev-parse -q --verify --symbolic-full-name 
--abbrev-ref "#{head}"`.chomp
+  if ! ref
     $stderr.puts "warn: No branch of #{url} is at:"
-    run("git show -s --format='warn:   %h: %s' #{headrev} >&2")
-    $stderr.puts "warn: Are you sure you pushed '#{short_headref}' there?"
+    run("git show -s --format='warn:   %h: %s' #{head} >&2")
+    $stderr.puts "warn: Are you sure you pushed '#{abbr(headref)}' there?"
     status = 1
   end
 rescue CommandError
-- 
1.8.4-fc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to