git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jakub Narebski <jnareb@gmail.com>
Date
Feb 10, 2009, 15:46 UTC
Message-ID
<m3ab8uuwfg.fsf@localhost.localdomain>
In-Reply-To
<1234273695-4981-1-git-send-email-pknotz@sandia.gov>
"Pat Notz" <pknotz@sandia.gov> writes:
Show 10 quoted lines
> 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.
Good idea, bad execution.
Show 17 quoted lines
> 
> Signed-off-by: Pat Notz <pknotz@sandia.gov>
> ---
>  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..116f89c 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) |
> +	this_branch=$(echo $refname | sed 's@refs/heads/@@')
> +	other_branches=$(git branch | sed 's/\*//g' | grep -v $this_branch)

git-branch is porcelain, git-branch is porcelain, git-branch is porcelain, git-branch is porcelain, git-branch is porcelain, git-branch is porcelain, git-branch is porcelain, git-branch is porcelain, ...

Don't use sed if shell will suffice...
Either:
+	this_branch=$refname
+	other_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |
+               grep -v $this_branch)
or

+ this_branch=${refname#refs/heads/} ...

Show 8 quoted lines
> +	git rev-parse --not $other_branches |
>  	if [ -z "$custom_showrev" ]
>  	then
>  		git rev-list --pretty --stdin $revspec
> -- 
> 1.6.1.2
> 
> 
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Pat NotzNext: Johannes Schindelin
Message 2 of 5 in “Fix contrib/hooks/post-receive-email for new branch with no new commits”
  1. Fix contrib/hooks/post-receive-email for new branch with no new commitsPat Notz, Feb 10, 2009
  2. Jakub NarebskiFeb 10, 2009
  3. Johannes SchindelinFeb 10, 2009
  4. Junio C HamanoFeb 10, 2009
  5. Fix contrib/hooks/post-receive-email for new duplicate branchPat Notz, Feb 10, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.