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

Re: git am from scratch

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 19, 2009, 21:57 UTC
Message-ID
<7vzlfh6uqn.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20090319210214.GA17589@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 5 quoted lines
> Anyway, here is a not-very-well-tested patch to get "git am" to apply on
> top of an empty repository (i.e., it worked on my utterly simplistic
> test case and I didn't think too hard about what else might have been
> broken). Maybe it will give a good start to somebody who wants to work
> on this.

The patch gets the ball rolling in a right direction, I think. In addition, you need to audit --abort and --skip codepaths carefully, though.

Show 52 quoted lines
> diff --git a/git-am.sh b/git-am.sh
> index d339075..bcc600d 100755
> --- a/git-am.sh
> +++ b/git-am.sh
> @@ -290,17 +290,23 @@ else
>  		: >"$dotest/rebasing"
>  	else
>  		: >"$dotest/applying"
> -		git update-ref ORIG_HEAD HEAD
> +		if git rev-parse --quiet --verify HEAD; then
> +			git update-ref ORIG_HEAD HEAD
> +		else
> +			rm -f "$GIT_DIR/ORIG_HEAD"
> +		fi
>  	fi
>  fi
>  
>  case "$resolved" in
>  '')
> -	files=$(git diff-index --cached --name-only HEAD --) || exit
> -	if test "$files"
> -	then
> -		: >"$dotest/dirtyindex"
> -		die "Dirty index: cannot apply patches (dirty: $files)"
> +	if git rev-parse --quiet --verify HEAD; then
> +		files=$(git diff-index --cached --name-only HEAD --) || exit
> +		if test "$files"
> +		then
> +			: >"$dotest/dirtyindex"
> +			die "Dirty index: cannot apply patches (dirty: $files)"
> +		fi
>  	fi
>  esac
>  
> @@ -541,7 +547,7 @@ do
>  	fi
>  
>  	tree=$(git write-tree) &&
> -	parent=$(git rev-parse --verify HEAD) &&
> +	parent=$(git rev-parse --quiet --verify HEAD)
>  	commit=$(
>  		if test -n "$ignore_date"
>  		then
> @@ -552,7 +558,7 @@ do
>  			GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
>  			export GIT_COMMITTER_DATE
>  		fi &&
> -		git commit-tree $tree -p $parent <"$dotest/final-commit"
> +		git commit-tree $tree ${parent:+-p $parent} <"$dotest/final-commit"
>  	) &&
>  	git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
>  	stop_here $this
Previous: Jeff KingNext: Andreas Gruenbacher
Message 6 of 8 in “git am from scratch”
  1. Andreas GruenbacherMar 19, 2009
  2. Eric RaibleMar 19, 2009
  3. Jeff KingMar 19, 2009
  4. Andreas GruenbacherMar 19, 2009
  5. Jeff KingMar 19, 2009
  6. Junio C HamanoMar 19, 2009
  7. Andreas GruenbacherMar 20, 2009
  8. Jeff KingMar 20, 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.