Re: [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] Fix contrib/hooks/post-receive-email for new branch with no new commits

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:46:08

Jakub Narebski [off-list ref] writes:
+	this_branch=$refname
+	other_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |
+               grep -v $this_branch)
This is still not quite right.  grep -F -v "$this_branch" perhaps?

[PATCH] Fix contrib/hooks/post-receive-email for new duplicate branch

From: Pat Notz <hidden>
Date: 2016-06-15 22:46:08

In the show_new_revisions function, the original code:

  git rev-parse --not --branches | grep -v $(git rev-parse $refname) |

isn't quite right since one can create a new branch and push it
without any new commits.  In that case, two refs will have the same
sha1 but both would get filtered by the 'grep'.  In the end, we'll
show ALL the history which is not what we want.  Instead, we should
list the branches by name and remove the branch being updated and THEN
pass that list through rev-parse.

Revised as suggested by Jakub Narebski and Junio C Hamano to use
git-for-each-ref instead of git-branch.  (Thanks!)

Signed-off-by: Pat Notz <redacted>
---
 contrib/hooks/post-receive-email |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 28a3c0e..60cbab6 100644
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -615,7 +615,9 @@ show_new_revisions()
 		revspec=$oldrev..$newrev
 	fi
 
-	git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
+	other_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |
+	    grep -F -v $refname)
+	git rev-parse --not $other_branches |
 	if [ -z "$custom_showrev" ]
 	then
 		git rev-list --pretty --stdin $revspec
-- 
1.6.1.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help