Re: [PATCH] git-am: Keep index in case of abort with dirty index

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Michael J Gruber <git@xxxxxxxxxxxxxxxxxxxx> writes:

> git am --abort resets the index unconditionally. But in case a previous
> git am exited due to a dirty index it is preferable to keep that index.
> Make it so.
>
> Signed-off-by: Michael J Gruber <git@xxxxxxxxxxxxxxxxxxxx>
> ---
> Something like this?

Thanks; I think it is a good start.

>  git-am.sh |   12 +++++++++---
>  1 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/git-am.sh b/git-am.sh
> index 8bcb206..7013fea 100755
> --- a/git-am.sh
> +++ b/git-am.sh
> @@ -230,8 +230,10 @@ then
>  		;;
>  	,t)
>  		git rerere clear
> -		git read-tree --reset -u HEAD ORIG_HEAD
> -		git reset ORIG_HEAD
> +		test -f "$dotest/dirtyindex" || {
> +			git read-tree --reset -u HEAD ORIG_HEAD
> +			git reset ORIG_HEAD
> +		}
>  		rm -fr "$dotest"
>  		exit ;;
>  	esac
> @@ -287,7 +289,11 @@ fi
>  case "$resolved" in
>  '')
>  	files=$(git diff-index --cached --name-only HEAD --) || exit
> -	test "$files" && die "Dirty index: cannot apply patches (dirty: $files)"
> +	if test "$files"
> +	then
> +		: >"$dotest/dirtyindex"
> +		die "Dirty index: cannot apply patches (dirty: $files)"
> +	fi
>  esac
>  
>  if test "$(cat "$dotest/utf8")" = t

This certainly would catch this case:

	$ git add hello.c
        $ git am -3 patch.mbox
        ... oops, I had already added my changes
        $ git am --abort

But I think there should be some other code that resets "dirtyindex" flag
file to deal with a case like this:

	... start from a clean index
	$ git am -3 patch.mbox
        ... applies a first few cleanly and creates commits
        ... then stops with a conflict
        $ edit hello.c
	$ git add hello.c
        ... conflict resolved and this is good
        $ git am
        ... oops, I meant --resolved
        $ git am --resolved
        ... goes a bit more and then gets another conflict
        ... after examining the situation, decide the whole series
        ... is not worth it
        $ git am --abort


I guess you would probably want this single liner on top of your patch
(not tested if it fixes the above sequence, though).

diff --git a/git-am.sh b/git-am.sh
index 7013fea..351b4f8 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -237,6 +237,7 @@ then
 		rm -fr "$dotest"
 		exit ;;
 	esac
+	rm -f "$dotest/dirtyindex"
 else
 	# Make sure we are not given --skip, --resolved, nor --abort
 	test "$skip$resolved$abort" = "" ||

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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux