From: Elijah Newren via GitGitGadget <hidden> Date: 2021-09-08 02:17:17
This series documents a few issues with git am --abort in the form of new
testcases, and fixes one of them. However, while I was surprised the abort
left the working directory dirty, I couldn't find any documentation to
confirm it should or shouldn't be, and reading the code led me to question
if perhaps it was intentional. Anyway, if it's intended, let me know and
I'll drop that testcase.
For frame of reference, these were some issues I found while working on
unintentional removal of untracked files/directories and the current working
directory, and I'm just submitting them separately.
Elijah Newren (2):
t4151: document a pair of am --abort bugs
am: fix incorrect exit status on am fail to abort
builtin/am.c | 3 ++-
t/t4151-am-abort.sh | 31 +++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
base-commit: e0a2f5cbc585657e757385ad918f167f519cfb96
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1087%2Fnewren%2Fam-issues-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1087/newren/am-issues-v1
Pull-Request: https://github.com/git/git/pull/1087
--
gitgitgadget
@@ -191,4 +195,31 @@ test_expect_success 'am --abort leaves index stat info alone' 'gitdiff-files--exit-code--quiet'+test_expect_failure'git am --abort return failed exit status when it fails''+test_when_finished"rm -rf file-2/ && git reset --hard"&&+gitcheckoutchanges&&+gitformat-patch-1--stdoutconflicting>changes.mbox&&+test_must_failgitam--3waychanges.mbox&&++gitrmfile-2&&+mkdirfile-2&&+echoprecious>file-2/somefile&&+test_must_failgitam--abort&&+test_path_is_dirfile-2/+'++test_expect_failure'git am --abort returns us to a clean state''+gitcheckoutchanges&&+gitformat-patch-1--stdoutconflicting>changes.mbox&&+test_must_failgitam--3waychanges.mbox&&++# Make a change related to the rest of the am work+echorelatedchange>>file-2&&++# Abort, and expect the related change to go away too+gitam--abort&&+gitstatus--porcelain-uno>actual&&+test_must_be_emptyactual+'+ test_done
@@ -195,7 +195,7 @@ test_expect_success 'am --abort leaves index stat info alone' 'gitdiff-files--exit-code--quiet'-test_expect_failure'git am --abort return failed exit status when it fails''+test_expect_success'git am --abort return failed exit status when it fails''test_when_finished"rm -rf file-2/ && git reset --hard"&&gitcheckoutchanges&&gitformat-patch-1--stdoutconflicting>changes.mbox&&
@@ -191,4 +195,31 @@ test_expect_success 'am --abort leaves index stat info alone' 'gitdiff-files--exit-code--quiet'+test_expect_failure'git am --abort return failed exit status when it fails''+test_when_finished"rm -rf file-2/ && git reset --hard"&&+gitcheckoutchanges&&+gitformat-patch-1--stdoutconflicting>changes.mbox&&+test_must_failgitam--3waychanges.mbox&&++gitrmfile-2&&+mkdirfile-2&&+echoprecious>file-2/somefile&&+test_must_failgitam--abort&&+test_path_is_dirfile-2/+'++test_expect_failure'git am --abort returns us to a clean state''+gitcheckoutchanges&&+gitformat-patch-1--stdoutconflicting>changes.mbox&&+test_must_failgitam--3waychanges.mbox&&++# Make a change related to the rest of the am work+echorelatedchange>>file-2&&++# Abort, and expect the related change to go away too+gitam--abort&&+gitstatus--porcelain-uno>actual&&+test_must_be_emptyactual+'+test_done
I expect BUGS section in git-am(1) to be added to describe known bugs
you demonstrated above, judging from the patch subject.
--
An old man doll... just what I always wanted! - Clara
@@ -191,4 +195,31 @@ test_expect_success 'am --abort leaves index stat info alone' 'gitdiff-files--exit-code--quiet'+test_expect_failure'git am --abort return failed exit status when it fails''+test_when_finished"rm -rf file-2/ && git reset --hard"&&+gitcheckoutchanges&&+gitformat-patch-1--stdoutconflicting>changes.mbox&&+test_must_failgitam--3waychanges.mbox&&++gitrmfile-2&&+mkdirfile-2&&+echoprecious>file-2/somefile&&+test_must_failgitam--abort&&+test_path_is_dirfile-2/+'++test_expect_failure'git am --abort returns us to a clean state''+gitcheckoutchanges&&+gitformat-patch-1--stdoutconflicting>changes.mbox&&+test_must_failgitam--3waychanges.mbox&&++# Make a change related to the rest of the am work+echorelatedchange>>file-2&&++# Abort, and expect the related change to go away too+gitam--abort&&+gitstatus--porcelain-uno>actual&&+test_must_be_emptyactual+'+test_done
I expect BUGS section in git-am(1) to be added to describe known bugs
you demonstrated above, judging from the patch subject.
There's no point documenting the first one since it'll be fixed by the
next patch. As for the second, as I noted in my cover letter, I'm not
quite sure that it really is a bug. If it isn't, the second testcase
should be dropped. However, if the second testcase represents an
actual bug rather than me just misjudging the intent, then your
suggestion certainly makes sense.
From: Johannes Schindelin <hidden> Date: 2021-09-08 08:08:44
Hi Elijah,
On Wed, 8 Sep 2021, Elijah Newren via GitGitGadget wrote:
This series documents a few issues with git am --abort in the form of new
testcases, and fixes one of them. However, while I was surprised the abort
left the working directory dirty, I couldn't find any documentation to
confirm it should or shouldn't be, and reading the code led me to question
if perhaps it was intentional. Anyway, if it's intended, let me know and
I'll drop that testcase.
As far as I understand, `git am --abort` should indeed clean up. The
behavior you described is what I would expect more of `git am --quit`.
The patches look good to me.
Thanks!
Dscho
For frame of reference, these were some issues I found while working on
unintentional removal of untracked files/directories and the current working
directory, and I'm just submitting them separately.
Elijah Newren (2):
t4151: document a pair of am --abort bugs
am: fix incorrect exit status on am fail to abort
builtin/am.c | 3 ++-
t/t4151-am-abort.sh | 31 +++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
base-commit: e0a2f5cbc585657e757385ad918f167f519cfb96
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1087%2Fnewren%2Fam-issues-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1087/newren/am-issues-v1
Pull-Request: https://github.com/git/git/pull/1087
--
gitgitgadget
From: Elijah Newren via GitGitGadget <hidden> Date: 2021-09-10 10:31:20
This series documents a few issues with git am --abort in the form of new
testcases, and fixes one of them. However, while I was surprised the abort
left the working directory dirty, I couldn't find any documentation to
confirm it should or shouldn't be, and reading the code led me to question
if perhaps it was intentional. Anyway, if it's intended, let me know and
I'll drop that testcase.
For frame of reference, these were some issues I found while working on
unintentional removal of untracked files/directories and the current working
directory, and I'm just submitting them separately.
Changes since v1:
* Added a patch to tweak the documentation to clarify that partial cleaning
of worktree is expected with --abort
* Tweaked the second test to be a test that unrelated dirty files are kept,
as suggested by Junio
Elijah Newren (3):
git-am.txt: clarify --abort behavior
t4151: add a few am --abort tests
am: fix incorrect exit status on am fail to abort
Documentation/git-am.txt | 2 ++
builtin/am.c | 3 ++-
t/t4151-am-abort.sh | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
base-commit: e0a2f5cbc585657e757385ad918f167f519cfb96
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1087%2Fnewren%2Fam-issues-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1087/newren/am-issues-v2
Pull-Request: https://github.com/git/git/pull/1087
Range-diff vs v1:
-: ----------- > 1: e199df0f3bc git-am.txt: clarify --abort behavior
1: b8a418bc63a ! 2: 38a7063b959 t4151: document a pair of am --abort bugs
@@ Metadata
Author: Elijah Newren [off-list ref]
## Commit message ##
- t4151: document a pair of am --abort bugs
+ t4151: add a few am --abort tests
Signed-off-by: Elijah Newren [off-list ref]
@@ t/t4151-am-abort.sh: test_expect_success setup '
git format-patch --no-numbered initial &&
+ git checkout -b conflicting initial &&
+ echo different >>file-1 &&
-+ git commit -a -m different &&
++ echo whatever >new-file &&
++ git add file-1 new-file &&
++ git commit -m different &&
git checkout -b side initial &&
echo local change >file-2-expect
'
@@ t/t4151-am-abort.sh: test_expect_success 'am --abort leaves index stat info alon
'
+test_expect_failure 'git am --abort return failed exit status when it fails' '
-+ test_when_finished "rm -rf file-2/ && git reset --hard" &&
++ test_when_finished "rm -rf file-2/ && git reset --hard && git am --abort" &&
+ git checkout changes &&
+ git format-patch -1 --stdout conflicting >changes.mbox &&
+ test_must_fail git am --3way changes.mbox &&
@@ t/t4151-am-abort.sh: test_expect_success 'am --abort leaves index stat info alon
+ test_path_is_dir file-2/
+'
+
-+test_expect_failure 'git am --abort returns us to a clean state' '
++test_expect_success 'git am --abort cleans relevant files' '
+ git checkout changes &&
+ git format-patch -1 --stdout conflicting >changes.mbox &&
+ test_must_fail git am --3way changes.mbox &&
+
-+ # Make a change related to the rest of the am work
-+ echo related change >>file-2 &&
++ test_path_is_file new-file &&
++ echo further changes >>file-1 &&
++ echo change other file >>file-2 &&
+
-+ # Abort, and expect the related change to go away too
++ # Abort, and expect the files touched by am to be reverted
+ git am --abort &&
-+ git status --porcelain -uno >actual &&
-+ test_must_be_empty actual
++
++ test_path_is_missing new-file &&
++
++ # Files not involved in am operation are left modified
++ git diff --name-only changes >actual &&
++ test_write_lines file-2 >expect &&
++ test_cmp expect actual
+'
+
test_done
2: 5fa7daf264b ! 3: a46f5c79fbf am: fix incorrect exit status on am fail to abort
@@ t/t4151-am-abort.sh: test_expect_success 'am --abort leaves index stat info alon
-test_expect_failure 'git am --abort return failed exit status when it fails' '
+test_expect_success 'git am --abort return failed exit status when it fails' '
- test_when_finished "rm -rf file-2/ && git reset --hard" &&
+ test_when_finished "rm -rf file-2/ && git reset --hard && git am --abort" &&
git checkout changes &&
git format-patch -1 --stdout conflicting >changes.mbox &&
--
gitgitgadget
From: Elijah Newren via GitGitGadget <hidden> Date: 2021-09-10 10:31:21
From: Elijah Newren <redacted>
Both Johannes and I assumed (perhaps due to familiarity with rebase)
that am --abort would return the user to a clean state. However, since
am, unlike rebase, is intended to be used within a dirty working tree,
--abort will only clean the files involved in the am operation.
Signed-off-by: Elijah Newren <redacted>
---
Documentation/git-am.txt | 2 ++
1 file changed, 2 insertions(+)
@@ -178,6 +178,8 @@ default. You can use `--no-utf8` to override this. --abort:: Restore the original branch and abort the patching operation.+ Revert contents of files involved in the am operation to their+ pre-am state. --quit:: Abort the patching operation but keep HEAD and the index
@@ -191,4 +197,37 @@ test_expect_success 'am --abort leaves index stat info alone' 'gitdiff-files--exit-code--quiet'+test_expect_failure'git am --abort return failed exit status when it fails''+test_when_finished"rm -rf file-2/ && git reset --hard && git am --abort"&&+gitcheckoutchanges&&+gitformat-patch-1--stdoutconflicting>changes.mbox&&+test_must_failgitam--3waychanges.mbox&&++gitrmfile-2&&+mkdirfile-2&&+echoprecious>file-2/somefile&&+test_must_failgitam--abort&&+test_path_is_dirfile-2/+'++test_expect_success'git am --abort cleans relevant files''+gitcheckoutchanges&&+gitformat-patch-1--stdoutconflicting>changes.mbox&&+test_must_failgitam--3waychanges.mbox&&++test_path_is_filenew-file&&+echofurtherchanges>>file-1&&+echochangeotherfile>>file-2&&++# Abort, and expect the files touched by am to be reverted+gitam--abort&&++test_path_is_missingnew-file&&++# Files not involved in am operation are left modified+gitdiff--name-onlychanges>actual&&+test_write_linesfile-2>expect&&+test_cmpexpectactual+'+ test_done
@@ -197,7 +197,7 @@ test_expect_success 'am --abort leaves index stat info alone' 'gitdiff-files--exit-code--quiet'-test_expect_failure'git am --abort return failed exit status when it fails''+test_expect_success'git am --abort return failed exit status when it fails''test_when_finished"rm -rf file-2/ && git reset --hard && git am --abort"&&gitcheckoutchanges&&gitformat-patch-1--stdoutconflicting>changes.mbox&&
From: Johannes Schindelin <hidden> Date: 2021-09-13 12:08:56
Hi Elijah,
On Fri, 10 Sep 2021, Elijah Newren via GitGitGadget wrote:
This series documents a few issues with git am --abort in the form of new
testcases, and fixes one of them. However, while I was surprised the abort
left the working directory dirty, I couldn't find any documentation to
confirm it should or shouldn't be, and reading the code led me to question
if perhaps it was intentional. Anyway, if it's intended, let me know and
I'll drop that testcase.
For frame of reference, these were some issues I found while working on
unintentional removal of untracked files/directories and the current working
directory, and I'm just submitting them separately.
Changes since v1:
* Added a patch to tweak the documentation to clarify that partial cleaning
of worktree is expected with --abort
* Tweaked the second test to be a test that unrelated dirty files are kept,
as suggested by Junio
FWIW I gave this a light read-over and am happy with it!
Ciao,
Dscho