From: Junio C Hamano <hidden> Date: 2016-06-15 22:44:57
Theodore Tso [off-list ref] writes:
While you have "git am" open, how about adding an "git am --abort"
which nukes the .dotest aka .git/rebase directory, and resets HEAD
back to the original position?
This does not seem to have reached the list nor its archives. I cannot
say I have really looked at it deeply but it may be a good starting
point. It needs docs ;-)
-- >8 --
From: Nanako Shiraishi <redacted>
Date: Wed, 16 Jul 2008 19:39:10 +0900
Subject: [PATCH] git am --abort
After failing to apply patches in the middle of a series, "git am --abort"
lets you go back to the original commit.
Signed-off-by: Nanako Shiraishi <redacted>
---
git-am.sh | 19 +++++++++++++++----
t/t4151-am-abort.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 4 deletions(-)
create mode 100755 t/t4151-am-abort.sh
@@ -22,6 +22,7 @@ p= pass it through git-applyresolvemsg=overrideerrormessagewhenpatchfailureoccurs r,resolvedtobeusedafterapatchfailure skipskipthecurrentpatch+abortabandonpatchapplicationandclear.dotestdirectory rebasing(internaluseforgit-rebase)" .git-sh-setup
@@ -120,7 +121,7 @@ It does not apply to blobs recorded in its index."prec=4dotest="$GIT_DIR/rebase"-sign=utf8=tkeep=skip=interactive=resolved=binary=rebasing=+sign=utf8=tkeep=skip=interactive=resolved=binary=rebasing=abort=resolvemsg=resume=git_apply_opt=
@@ -177,7 +180,7 @@ fiiftest-d"$dotest"then-case"$#,$skip$resolved"in+case"$#,$skip$resolved$abort"in0,*t*)# Explicit resume command and we do not have file, so# we are happy.
@@ -197,9 +200,17 @@ thenesac||die"previous rebase directory $dotest still exists but mbox given."resume=yes++case"$abort"in+t)+rm-fr"$dotest"&&+gitread-tree-m-uORIG_HEAD&&+gitresetORIG_HEAD&&:+exit;;+esacelse-# Make sure we are not given --skip nor --resolved-test",$skip,$resolved,"=,,,||+# Make sure we are not given --skip, --resolved, nor --abort+test"$skip$resolved$abort"=""||die"Resolve operation not in progress, we are not resuming."# Start afresh.
@@ -0,0 +1,48 @@+#!/bin/sh++test_description='am --abort'++../test-lib.sh++test_expect_successsetup'+foriinabcdefg+do+echo$i+done>file-1&&+cpfile-1file-2&&+test_tick&&+gitaddfile-1file-2&&+gitcommit-minitial&&+gittaginitial&&+foriin2345+do+echo$i>>file-1&&+test_tick&&+gitcommit-a-m$i||break+done&&+gitformat-patchinitial&&+gitcheckout-bsideinitial&&+echolocalchange>file-2&&+cpfile-2file-2-expect+'++test_expect_success'am stops at a patch that does not apply''+test_must_failgitam000[124]-*.patch&&+gitlog--pretty=tformat:%s>actual&&+foriin32initial+do+echo$i+done>expect&&+test_cmpexpectactual+'++test_expect_success'am --abort goes back''+gitam--abort&&+gitrev-parseHEAD>actual&&+gitrev-parseinitial>expect&&+test_cmpexpectactual&&+test_cmpfile-2-expectfile-2&&+gitdiff-index--exit-code--cachedHEAD+'++test_done
While you have "git am" open, how about adding an "git am --abort"
which nukes the .dotest aka .git/rebase directory, and resets HEAD
back to the original position?
This does not seem to have reached the list nor its archives. I cannot
say I have really looked at it deeply but it may be a good starting
point. It needs docs ;-)
This can be squashed to Nanako's path: it adds missing docs,
'git rerere clear' and move $dotest deletion at the end in case
'git read-tree' failed (because of a dirty index).
Olivier.
-- >8 --
Subject: [PATCH] git am --abort
To squash.
Signed-off-by: Olivier Marin <redacted>
---
Documentation/git-am.txt | 5 ++++-
git-am.sh | 8 +++++---
2 files changed, 9 insertions(+), 4 deletions(-)
@@ -99,6 +99,9 @@ default. You could use `--no-utf8` to override this. or `--skip` to handle the failure. This is solely for internal use between 'git-rebase' and 'git-am'.+--abort::+ Restore the original branch and abort the patching operation.+ DISCUSSION ----------
@@ -22,7 +22,7 @@ p= pass it through git-applyresolvemsg=overrideerrormessagewhenpatchfailureoccurs r,resolvedtobeusedafterapatchfailure skipskipthecurrentpatch-abortabandonpatchapplicationandclear.dotestdirectory+abortrestoretheoriginalbranchandabortthepatchingoperation. rebasing(internaluseforgit-rebase)" .git-sh-setup
@@ -55,6 +55,7 @@ stop_here_user_resolve () {fiecho"When you have resolved this problem run \"$cmdline --resolved\"."echo"If you would prefer to skip this patch, instead run \"$cmdline --skip\"."+echo"To restore the original branch and stop patching run \"$cmdline --abort\"."stop_here$1}
While you have "git am" open, how about adding an "git am --abort"
which nukes the .dotest aka .git/rebase directory, and resets HEAD
back to the original position?
This does not seem to have reached the list nor its archives. I cannot
say I have really looked at it deeply but it may be a good starting
point. It needs docs ;-)
Thinking about the way "git am" works:
It tries to apply patches even on a dirty tree which makes difficult
to automatically do a "git reset --hard" with --skip or --abort and
forces the user to clean the index by hand if last patch failed with
unmerged files.
So, do some people still use "git am" with a dirty tree or will a
patch that make it work like "git rebase" be accepted?
I think users can use "git stash" and "git stash pop" today. Did I
miss something?
Note: the version that use "git sequencer" seems to work like I want
but I do not know if it is a side effect or not.
Olivier.
From: Stephan Beyer <hidden> Date: 2016-06-15 22:44:58
Hi,
Olivier Marin wrote:
Note: the version that use "git sequencer" seems to work like I want
but I do not know if it is a side effect or not.
If you mean with "work like I want" that it complains about an unclean
work tree: the check is explicitly done by git-sequencer.
I guess there are situations where you want to apply a patch on a dirty
work tree, e.g. if you fixed some tiny issues so that patches can
apply cleanly.
But I think it does not hurt to commit such tiny changes and perhaps
squash later.
Regards,
Stephan
--
Stephan Beyer [off-list ref], PGP 0x6EDDD207FCC5040F
If you mean with "work like I want" that it complains about an unclean
work tree: the check is explicitly done by git-sequencer.
Yes, I mean: refuse to work if the tree is not clean _and_ --skip
and --abort clean the index/tree for me.
With current git version "git am --skip" refuse to continue with a
message: "Dirty index: cannot apply patches (dirty: ...)", if some
files stay unmerged.
As a user I find --skip and --abort useless^Wpainful to use in this
situation.
I guess there are situations where you want to apply a patch on a dirty
work tree, e.g. if you fixed some tiny issues so that patches can
apply cleanly.
From: Junio C Hamano <hidden> Date: 2016-06-15 22:44:58
Olivier Marin [off-list ref] writes:
It tries to apply patches even on a dirty tree which makes difficult
to automatically do a "git reset --hard" with --skip or --abort and
forces the user to clean the index by hand if last patch failed with
unmerged files.
So, do some people still use "git am" with a dirty tree or will a
patch that make it work like "git rebase" be accepted?
Anything that changes "am" to require a clean working tree will NEVER be
accepted. I personally rely on the ability for it to run in a dirty tree,
so does Linus.
Side note. Anything that changes "merge" to require a clean
working tree is also unacceptable. Cf.
http://thread.gmane.org/gmane.comp.version-control.git/9073/focus=9089
Linus talks about "patch" in the paragraph second to the last one
in the message; back then he was talking about "git-applymbox" but
the same argument there applies to its newer incarnation "git-am".
Side note #2. It would have been nice if "rebase" were also
written in such a way that it can work in a dirty tree as long as
local changes did not interfere with the operation, but it is a
lot more involved.
When I looked at the "am --abort" patch briefly, I had an impression (by
reading its test case) that it correctly refrained from doing the
destructive "reset --hard".
From: Jakub Narebski <hidden> Date: 2016-06-15 22:44:58
[This is git@vger.kernel.org only copy]
Junio C Hamano wrote:
Olivier Marin [off-list ref] writes:
quoted
It tries to apply patches even on a dirty tree which makes difficult
to automatically do a "git reset --hard" with --skip or --abort and
forces the user to clean the index by hand if last patch failed with
unmerged files.
So, do some people still use "git am" with a dirty tree or will a
patch that make it work like "git rebase" be accepted?
Anything that changes "am" to require a clean working tree will NEVER be
accepted. I personally rely on the ability for it to run in a dirty tree,
so does Linus.
Side note. Anything that changes "merge" to require a clean
working tree is also unacceptable. Cf.
http://thread.gmane.org/gmane.comp.version-control.git/9073/focus=9089
Linus talks about "patch" in the paragraph second to the last one
in the message; back then he was talking about "git-applymbox" but
the same argument there applies to its newer incarnation "git-am".
Side note #2. It would have been nice if "rebase" were also
written in such a way that it can work in a dirty tree as long as
local changes did not interfere with the operation, but it is a
lot more involved.
When I looked at the "am --abort" patch briefly, I had an impression (by
reading its test case) that it correctly refrained from doing the
destructive "reset --hard".
I guess instead of "git reset --hard" we can use here "git stash save
&& git stash apply --index" to save state (perhaps as "git stash save
--no-reset"), and either "git stash drop" at the the end, or
"git reset --hard && git stash pop --index" at '--abort'.
--
Jakub Narebski
Poland
ShadeHawk on #git
Anything that changes "am" to require a clean working tree will NEVER be
accepted. I personally rely on the ability for it to run in a dirty tree,
so does Linus.
Side note. Anything that changes "merge" to require a clean
working tree is also unacceptable. Cf.
http://thread.gmane.org/gmane.comp.version-control.git/9073/focus=9089
Linus talks about "patch" in the paragraph second to the last one
in the message; back then he was talking about "git-applymbox" but
the same argument there applies to its newer incarnation "git-am".
Side note #2. It would have been nice if "rebase" were also
written in such a way that it can work in a dirty tree as long as
local changes did not interfere with the operation, but it is a
lot more involved.
Thanks for the explanation and the really interesting pointer.
The last thing that still annoy me is the --skip that refuse to skip in 3-way
merge. Perhaps we can use the "git read-tree --reset -u" thing for skip too.
So, what about the following patch?
-- >8 --
From: Olivier Marin <redacted>
git am --skip: clean the index while preserving local changes
In 3-way merge, "am" will let the index with unmerged path waiting
for us to resolve conflicts and continue. But if we want to --skip
instead, "am" refuses to continue because of the dirty index.
With this patch, "am" will clean the index without touching files
locally modified, before continue.
Signed-off-by: Olivier Marin <redacted>
---
git-am.sh | 12 +++++++++---
t/t4151-am-abort.sh | 11 +++++++++--
2 files changed, 18 insertions(+), 5 deletions(-)
@@ -202,8 +202,15 @@ thendie"previous rebase directory $dotest still exists but mbox given."resume=yes-case"$abort"in-t)+case"$skip,$abort"in+t,)+gitrerereclear+gitread-tree--reset-uHEADHEAD+orig_head=$(cat"$GIT_DIR/ORIG_HEAD")+gitresetHEAD+gitupdate-refORIG_HEAD$orig_head+;;+,t)gitrererecleargitread-tree--reset-uHEADORIG_HEADgitresetORIG_HEAD
From: Stephan Beyer <hidden> Date: 2016-06-15 22:44:59
The git-rerere documentation talks about commands that invoke
"git rerere clear" automatically. git am --abort is added and
a typo is fixed additionally.
Signed-off-by: Stephan Beyer <redacted>
---
Documentation/git-rerere.txt | 2 +-
contrib/completion/git-completion.bash | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
@@ -37,7 +37,7 @@ its working state. 'clear':: This resets the metadata used by rerere if a merge resolution is to be-is aborted. Calling 'git-am --skip' or 'git-rebase [--skip|--abort]'+aborted. Calling 'git-am [--skip|--abort]' or 'git-rebase [--skip|--abort]' will automatically invoke this command. 'diff'::
From: Junio C Hamano <hidden> Date: 2016-06-15 22:44:59
Olivier Marin [off-list ref] writes:
The last thing that still annoy me is the --skip that refuse to skip in 3-way
merge. Perhaps we can use the "git read-tree --reset -u" thing for skip too.
Hmm...
We traditionally left that as something the user deliberately should do to
signal --skip that the user knows he is dropping that change (by the way,
so did "git-rebase"). But with fb6e4e1 (Do git reset --hard HEAD when
using git rebase --skip, 2007-11-08), we run the reset upon rebase --skip,
so it probably is a good idea to match it here as well.
@@ -202,8 +202,15 @@ thendie"previous rebase directory $dotest still exists but mbox given."resume=yes-case"$abort"in-t)+case"$skip,$abort"in+t,)+gitrerereclear+gitread-tree--reset-uHEADHEAD+orig_head=$(cat"$GIT_DIR/ORIG_HEAD")+gitresetHEAD+gitupdate-refORIG_HEAD$orig_head+;;
Sorry, I do not quite understand what this reset after the read-tree dance
is trying to do; you have already reset the index to the tree in HEAD when
you cleared the change involved in the patch application with that
two-tree form of read-tree.
@@ -202,8 +202,15 @@ thendie"previous rebase directory $dotest still exists but mbox given."resume=yes-case"$abort"in-t)+case"$skip,$abort"in+t,)+gitrerereclear+gitread-tree--reset-uHEADHEAD+orig_head=$(cat"$GIT_DIR/ORIG_HEAD")+gitresetHEAD+gitupdate-refORIG_HEAD$orig_head+;;
Sorry, I do not quite understand what this reset after the read-tree dance
is trying to do; you have already reset the index to the tree in HEAD when
you cleared the change involved in the patch application with that
two-tree form of read-tree.
I add reset to unstage paths with no conflict that are left behind. Perhaps
read-tree can clear those paths as well but I do not know how, the man page
is hard to follow.
--
Olivier.
From: Junio C Hamano <hidden> Date: 2016-06-15 22:45:00
Olivier Marin [off-list ref] writes:
Junio C Hamano a écrit :
quoted
quoted
diff --git a/git-am.sh b/git-am.sh
...
quoted
@@ -202,8 +202,15 @@ then
...
quoted
+ case "$skip,$abort" in
+ t,)
+ git rerere clear
+ git read-tree --reset -u HEAD HEAD
+ orig_head=$(cat "$GIT_DIR/ORIG_HEAD")
+ git reset HEAD
+ git update-ref ORIG_HEAD $orig_head
+ ;;
...
I add reset to unstage paths with no conflict that are left behind.
Does removing the last three lines (1) change the behaviour? (2) break any test?
If the answers are "Yes and No", we would need a few more tests in the
testsuite.
If the answers are "No and naturally no", then let's remove the last three
lines in the hunk.
+ case "$skip,$abort" in
+ t,)
+ git rerere clear
+ git read-tree --reset -u HEAD HEAD
+ orig_head=$(cat "$GIT_DIR/ORIG_HEAD")
+ git reset HEAD
+ git update-ref ORIG_HEAD $orig_head
+ ;;
...
I add reset to unstage paths with no conflict that are left behind.
Does removing the last three lines (1) change the behaviour? (2) break any test?
If the answers are "Yes and No", we would need a few more tests in the
testsuite.
The answers are "Yes and No" and test case update follow.
-- >8 --
From: Olivier Marin <redacted>
[PATCH] update test case to protect am --skip behaviour
Signed-off-by: Olivier Marin <redacted>
---
t/t4151-am-abort.sh | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)