Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Andreas Gruenbacher <agruen@suse.de>, git@vger.kernel.org
Subject: Re: git am from scratch
Date: Thu, 19 Mar 2009 14:57:52 -0700	[thread overview]
Message-ID: <7vzlfh6uqn.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20090319210214.GA17589@coredump.intra.peff.net> (Jeff King's message of "Thu, 19 Mar 2009 17:02:14 -0400")

Jeff King <peff@peff.net> writes:

> 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.

> 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

  reply	other threads:[~2009-03-19 22:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-19 15:09 git am from scratch Andreas Gruenbacher
2009-03-19 16:16 ` Eric Raible
2009-03-19 20:18 ` Jeff King
2009-03-19 20:42   ` Andreas Gruenbacher
2009-03-19 21:02     ` Jeff King
2009-03-19 21:57       ` Junio C Hamano [this message]
2009-03-20  1:06       ` Andreas Gruenbacher
2009-03-20  4:39         ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vzlfh6uqn.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=agruen@suse.de \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox