* [BUG] assertion failure in builtin-mv.c with "git mv -k" @ 2009-01-14 13:20 Matthieu Moy 2009-01-14 14:53 ` Michael J Gruber 2009-01-14 15:42 ` [PATCH] fix handling of multiple untracked files for git mv -k Michael J Gruber 0 siblings, 2 replies; 14+ messages in thread From: Matthieu Moy @ 2009-01-14 13:20 UTC (permalink / raw) To: git Hi, Just found a bug in builtin-mv.c. Here's a script to reproduce: mkdir git cd git git init touch controled git add controled && git commit -m "init" touch foo1 foo2 mkdir dir git mv -k foo* dir/ The output is the following: Initialized empty Git repository in /tmp/git/.git/ [master (root-commit)]: created 694563b: "init" 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 controled git: builtin-mv.c:216: cmd_mv: Assertion `pos >= 0' failed. ./bug.sh: line 10: 12919 Aborted git mv -k foo* dir/ Apparently, this happens when using "git mv -k" with more than one unversionned file. The code ignores the first one, but still goes through this for (i = 0; i < argc; i++) { const char *src = source[i], *dst = destination[i]; enum update_mode mode = modes[i]; int pos; if (show_only || verbose) printf("Renaming %s to %s\n", src, dst); if (!show_only && mode != INDEX && rename(src, dst) < 0 && !ignore_errors) die ("renaming %s failed: %s", src, strerror(errno)); if (mode == WORKING_DIRECTORY) continue; pos = cache_name_pos(src, strlen(src)); assert(pos >= 0); /* <----- this is the one */ if (!show_only) rename_cache_entry_at(pos, dst); } for the second, and it crashes on the assertion (gdb says "pos" here is an unversionned file name). If anyone has time to fix this ... Thanks, -- Matthieu ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [BUG] assertion failure in builtin-mv.c with "git mv -k" 2009-01-14 13:20 [BUG] assertion failure in builtin-mv.c with "git mv -k" Matthieu Moy @ 2009-01-14 14:53 ` Michael J Gruber 2009-01-14 15:54 ` Johannes Schindelin 2009-01-14 15:42 ` [PATCH] fix handling of multiple untracked files for git mv -k Michael J Gruber 1 sibling, 1 reply; 14+ messages in thread From: Michael J Gruber @ 2009-01-14 14:53 UTC (permalink / raw) To: Matthieu Moy; +Cc: git Matthieu Moy venit, vidit, dixit 14.01.2009 14:20: > Hi, > > Just found a bug in builtin-mv.c. Here's a script to reproduce: > > mkdir git > cd git > git init > touch controled > git add controled && git commit -m "init" > touch foo1 foo2 > mkdir dir > git mv -k foo* dir/ > > The output is the following: > > Initialized empty Git repository in /tmp/git/.git/ > [master (root-commit)]: created 694563b: "init" > 0 files changed, 0 insertions(+), 0 deletions(-) > create mode 100644 controled > git: builtin-mv.c:216: cmd_mv: Assertion `pos >= 0' failed. > ./bug.sh: line 10: 12919 Aborted git mv -k foo* dir/ > > Apparently, this happens when using "git mv -k" with more than one > unversionned file. The code ignores the first one, but still goes > through this > > for (i = 0; i < argc; i++) { > const char *src = source[i], *dst = destination[i]; > enum update_mode mode = modes[i]; > int pos; > if (show_only || verbose) > printf("Renaming %s to %s\n", src, dst); > if (!show_only && mode != INDEX && > rename(src, dst) < 0 && !ignore_errors) > die ("renaming %s failed: %s", src, strerror(errno)); > > if (mode == WORKING_DIRECTORY) > continue; > > pos = cache_name_pos(src, strlen(src)); > assert(pos >= 0); /* <----- this is the one */ > if (!show_only) > rename_cache_entry_at(pos, dst); > } > > for the second, and it crashes on the assertion (gdb says "pos" here > is an unversionned file name). > > If anyone has time to fix this ... > > Thanks, > The problem is actually in the loop before, with just one line missing. I'll send a patch but I'm not sure if this needs a test case. Michael ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [BUG] assertion failure in builtin-mv.c with "git mv -k" 2009-01-14 14:53 ` Michael J Gruber @ 2009-01-14 15:54 ` Johannes Schindelin 2009-01-14 16:04 ` Michael J Gruber 2009-01-14 17:03 ` [PATCH v2 0/3] Add test cases for "git mv -k" and fix a known breakage Michael J Gruber 0 siblings, 2 replies; 14+ messages in thread From: Johannes Schindelin @ 2009-01-14 15:54 UTC (permalink / raw) To: Michael J Gruber; +Cc: Matthieu Moy, git Hi, On Wed, 14 Jan 2009, Michael J Gruber wrote: > I'll send a patch but I'm not sure if this needs a test case. Umm, Michael, you have been here long enough to know that the answer is a "YES!". If you fix something, you want to provide a test case just to make sure you do not need to fix it again later. Ciao, Dscho ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [BUG] assertion failure in builtin-mv.c with "git mv -k" 2009-01-14 15:54 ` Johannes Schindelin @ 2009-01-14 16:04 ` Michael J Gruber 2009-01-14 16:47 ` Jeff King 2009-01-14 19:02 ` Junio C Hamano 2009-01-14 17:03 ` [PATCH v2 0/3] Add test cases for "git mv -k" and fix a known breakage Michael J Gruber 1 sibling, 2 replies; 14+ messages in thread From: Michael J Gruber @ 2009-01-14 16:04 UTC (permalink / raw) To: Johannes Schindelin; +Cc: Matthieu Moy, git Johannes Schindelin venit, vidit, dixit 14.01.2009 16:54: > Hi, > > On Wed, 14 Jan 2009, Michael J Gruber wrote: > >> I'll send a patch but I'm not sure if this needs a test case. > > Umm, Michael, you have been here long enough to know that the answer is a > "YES!". If you fix something, you want to provide a test case just to > make sure you do not need to fix it again later. > > Ciao, > Dscho > It was a lame attempt at getting around it, it's just one line... I didn't know I've been being noticed long enough ;) So, should I prepare a series like: 1: test case and mark known fail 2: the 1 line fix 3: mark test pass Or should 2+3 be squashed into one? Cheers, Michael ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [BUG] assertion failure in builtin-mv.c with "git mv -k" 2009-01-14 16:04 ` Michael J Gruber @ 2009-01-14 16:47 ` Jeff King 2009-01-14 19:02 ` Junio C Hamano 1 sibling, 0 replies; 14+ messages in thread From: Jeff King @ 2009-01-14 16:47 UTC (permalink / raw) To: Michael J Gruber; +Cc: Johannes Schindelin, Matthieu Moy, git On Wed, Jan 14, 2009 at 05:04:44PM +0100, Michael J Gruber wrote: > It was a lame attempt at getting around it, it's just one line... I > didn't know I've been being noticed long enough ;) > So, should I prepare a series like: > > 1: test case and mark known fail > 2: the 1 line fix > 3: mark test pass > > Or should 2+3 be squashed into one? Definitely the fix and marking the test as passing should be one patch, since then you see that it is the fix which causes the test to pass. But really, for a simple fix I usually just squash it all into a single patch. Then somebody looking at the patch later says "Oh, this is what was broken, and here is how it was fixed." -Peff ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [BUG] assertion failure in builtin-mv.c with "git mv -k" 2009-01-14 16:04 ` Michael J Gruber 2009-01-14 16:47 ` Jeff King @ 2009-01-14 19:02 ` Junio C Hamano 2009-01-15 10:53 ` Michael J Gruber 1 sibling, 1 reply; 14+ messages in thread From: Junio C Hamano @ 2009-01-14 19:02 UTC (permalink / raw) To: Michael J Gruber; +Cc: Johannes Schindelin, Matthieu Moy, git Michael J Gruber <git@drmicha.warpmail.net> writes: > So, should I prepare a series like: > > 1: test case and mark known fail > 2: the 1 line fix > 3: mark test pass > > Or should 2+3 be squashed into one? If "git mv" already has its own sets of tests with a good coverage, please strive to add a case that covers your fix to an existing script. Then step #1 above would be a patch to add a few "test_expect_failure" tests to an existing file, and step #3 would be a patch to flip expect_failure to expect_success. And in such a case, for a single liner, all three can be squashed in to a single patch. It would show what changed in the code and have a few new test_expect_success tests added to the test suite, and it would be obvious to anybody who looks at such a change 6 months down the road that the test cases added by the patch are the cases that did not work without the changes to the code. It never makes sense to separate steps #2 and #3 for any fix. If "git mv" did not have adequate test coverage, then please add a test script with both expect_success (for cases that should have been there when somebody worked on "git mv" originally), and expect_failure to expose the bug you found in your first patch. Again, the second patch would update the code and flip expect_failure to expect_success. I see there is t7001-mv and even though it claims to concentrate on its operation from subdirectory, it has tests for more basic modes of the operation. So my recommendation would be to have a single patch that: (1) retitles t7001; (2) adds your new -k tests to it; and (3) adds the 1-liner fix. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [BUG] assertion failure in builtin-mv.c with "git mv -k" 2009-01-14 19:02 ` Junio C Hamano @ 2009-01-15 10:53 ` Michael J Gruber 2009-01-15 22:19 ` Junio C Hamano 0 siblings, 1 reply; 14+ messages in thread From: Michael J Gruber @ 2009-01-15 10:53 UTC (permalink / raw) To: Junio C Hamano; +Cc: Johannes Schindelin, Matthieu Moy, git Junio C Hamano venit, vidit, dixit 14.01.2009 20:02: ... > If "git mv" did not have adequate test coverage, then please add a test > script with both expect_success (for cases that should have been there > when somebody worked on "git mv" originally), and expect_failure to expose > the bug you found in your first patch. Again, the second patch would > update the code and flip expect_failure to expect_success. > > I see there is t7001-mv and even though it claims to concentrate on its > operation from subdirectory, it has tests for more basic modes of the > operation. > > So my recommendation would be to have a single patch that: > > (1) retitles t7001; > (2) adds your new -k tests to it; and > (3) adds the 1-liner fix. > Sorry to bother you again, even after your detailed reply, but I'm a bit confused in multiple ways (I guess that makes for multiple bits...). First, you replied to my post, not my patch v2, but (time-wise) after my patch v2, so I'm not sure whether your reply applies to v2 as well or that one is OK. Second, I took the title of t7001 to mean "mv into subdir" or "mv in and out subdir" in order to distiguish it from "mv oldname newname", albeit in English that leaves room from improvement. Third, various parts of that test are in vastly different styles, and I haven't found any test writing directions other than "follow what is there", which leaves several alternatives. (Some use the test-lib repo, some create their own underneath, some make assumptions about the contents of "$TEST_DIRECTORY"/../.) Fourth, t7001-mv is missing any test for "mv -k", and 2 of my 3 additional tests cover cases which work (pass) without the fix, which is why I kept it separate, being unrelated. Following all your arguments lead to the conclusion I should squash 2+3 (fix + mark expect_pass) - until I read your conclusion, which says squash all. I'm happy to follow any variant ("1+2+3", "1 2+3", "1 2 3", in increasing order of preference) so there's no need to discuss or explain this further, just tell me "do x" ;) Cheers, Michael ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [BUG] assertion failure in builtin-mv.c with "git mv -k" 2009-01-15 10:53 ` Michael J Gruber @ 2009-01-15 22:19 ` Junio C Hamano 2009-01-16 12:57 ` Matthieu Moy 0 siblings, 1 reply; 14+ messages in thread From: Junio C Hamano @ 2009-01-15 22:19 UTC (permalink / raw) To: Michael J Gruber; +Cc: Johannes Schindelin, Matthieu Moy, git Michael J Gruber <git@drmicha.warpmail.net> writes: > I'm happy to follow any variant ("1+2+3", "1 2+3", "1 2 3", in > increasing order of preference) so there's no need to discuss or explain > this further, just tell me "do x" ;) Do nothing ;-) Your 1=3772923 and 2+3=be17262d are already in and we can include the fix in the next 1.6.1.X maintenance release. Thanks. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [BUG] assertion failure in builtin-mv.c with "git mv -k" 2009-01-15 22:19 ` Junio C Hamano @ 2009-01-16 12:57 ` Matthieu Moy 0 siblings, 0 replies; 14+ messages in thread From: Matthieu Moy @ 2009-01-16 12:57 UTC (permalink / raw) To: Junio C Hamano; +Cc: Michael J Gruber, git Junio C Hamano <gitster@pobox.com> writes: > Michael J Gruber <git@drmicha.warpmail.net> writes: > >> I'm happy to follow any variant ("1+2+3", "1 2+3", "1 2 3", in >> increasing order of preference) so there's no need to discuss or explain >> this further, just tell me "do x" ;) > > Do nothing ;-) Your 1=3772923 and 2+3=be17262d are already in and we can > include the fix in the next 1.6.1.X maintenance release. Thanks! -- Matthieu ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 0/3] Add test cases for "git mv -k" and fix a known breakage. 2009-01-14 15:54 ` Johannes Schindelin 2009-01-14 16:04 ` Michael J Gruber @ 2009-01-14 17:03 ` Michael J Gruber 2009-01-14 17:03 ` [PATCH v2 1/3] add test cases for "git mv -k" Michael J Gruber 1 sibling, 1 reply; 14+ messages in thread From: Michael J Gruber @ 2009-01-14 17:03 UTC (permalink / raw) To: git; +Cc: Johannes Schindelin This adds test cases for the "-k" option of "git mv", including one known breakage reported by Matthieu Moy <Matthieu.Moy@imag.fr> which appears when multiple untracked files are specified as consecutive arguments. This breakage is fixed in the second patch and marked "expect_pass" in the last one. The cumulative code/other ratio is 1 line/27 lines which I blame solely on Dscho ;) Seriously, feel free to squash. But on the other hand: How else can I see the beautiful "1 known breakage fixed" other than by having 2 and 3 separate in this series... The patch is off master but builtin-mv.c hasn't changed since 81dc2307d0ad87a4da2e753a9d1b5586d6456eed tags/v1.6.0-rc1~1, so I suggest this patch for maint. Michael J Gruber (3): add test cases for "git mv -k" fix handling of multiple untracked files for git mv -k mark fixed breakage as expect pass for "git mv -k" multiple files builtin-mv.c | 1 + t/t7001-mv.sh | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-) ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 1/3] add test cases for "git mv -k" 2009-01-14 17:03 ` [PATCH v2 0/3] Add test cases for "git mv -k" and fix a known breakage Michael J Gruber @ 2009-01-14 17:03 ` Michael J Gruber 2009-01-14 17:03 ` [PATCH v2 2/3] fix handling of multiple untracked files for git mv -k Michael J Gruber 0 siblings, 1 reply; 14+ messages in thread From: Michael J Gruber @ 2009-01-14 17:03 UTC (permalink / raw) To: git; +Cc: Johannes Schindelin Add test cases for ignoring nonexisting and untracked files using the -k option to "git mv". There is one known breakage related to multiple untracked files specfied as consecutive arguments. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> --- t/t7001-mv.sh | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 575ef5b..5c1485d 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -39,6 +39,31 @@ test_expect_success \ grep "^R100..*path1/COPYING..*path0/COPYING"' test_expect_success \ + 'checking -k on non-existing file' \ + 'git mv -k idontexist path0' + +test_expect_success \ + 'checking -k on untracked file' \ + 'touch untracked1 && + git mv -k untracked1 path0 && + test -f untracked1 && + test ! -f path0/untracked1' + +test_expect_failure \ + 'checking -k on multiple untracked files' \ + 'touch untracked2 && + git mv -k untracked1 untracked2 path0 && + test -f untracked1 && + test -f untracked2 && + test ! -f path0/untracked1 + test ! -f path0/untracked2' + +# clean up the mess in case bad things happen +rm -f idontexist untracked1 untracked2 \ + path0/idontexist path0/untracked1 path0/untracked2 \ + .git/index.lock + +test_expect_success \ 'adding another file' \ 'cp "$TEST_DIRECTORY"/../README path0/README && git add path0/README && -- 1.6.0.6 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 2/3] fix handling of multiple untracked files for git mv -k 2009-01-14 17:03 ` [PATCH v2 1/3] add test cases for "git mv -k" Michael J Gruber @ 2009-01-14 17:03 ` Michael J Gruber 2009-01-14 17:03 ` [PATCH v2 3/3] mark fixed breakage as expect pass for "git mv -k" multiple files Michael J Gruber 0 siblings, 1 reply; 14+ messages in thread From: Michael J Gruber @ 2009-01-14 17:03 UTC (permalink / raw) To: git; +Cc: Johannes Schindelin The "-k" option to "git mv" should allow specifying multiple untracked files. Currently, multiple untracked files raise an assertion if they appear consecutively as arguments. Fix this by decrementing the loop index after removing one entry from the array of arguments. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> --- builtin-mv.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/builtin-mv.c b/builtin-mv.c index 4f65b5a..bce9959 100644 --- a/builtin-mv.c +++ b/builtin-mv.c @@ -192,6 +192,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) memmove(destination + i, destination + i + 1, (argc - i) * sizeof(char *)); + i--; } } else die ("%s, source=%s, destination=%s", -- 1.6.0.6 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 3/3] mark fixed breakage as expect pass for "git mv -k" multiple files 2009-01-14 17:03 ` [PATCH v2 2/3] fix handling of multiple untracked files for git mv -k Michael J Gruber @ 2009-01-14 17:03 ` Michael J Gruber 0 siblings, 0 replies; 14+ messages in thread From: Michael J Gruber @ 2009-01-14 17:03 UTC (permalink / raw) To: git; +Cc: Johannes Schindelin The new tests pass now so mark them as such. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> --- t/t7001-mv.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 5c1485d..ef2e78f 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -49,7 +49,7 @@ test_expect_success \ test -f untracked1 && test ! -f path0/untracked1' -test_expect_failure \ +test_expect_success \ 'checking -k on multiple untracked files' \ 'touch untracked2 && git mv -k untracked1 untracked2 path0 && -- 1.6.0.6 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH] fix handling of multiple untracked files for git mv -k 2009-01-14 13:20 [BUG] assertion failure in builtin-mv.c with "git mv -k" Matthieu Moy 2009-01-14 14:53 ` Michael J Gruber @ 2009-01-14 15:42 ` Michael J Gruber 1 sibling, 0 replies; 14+ messages in thread From: Michael J Gruber @ 2009-01-14 15:42 UTC (permalink / raw) To: git; +Cc: Junio C Hamano The "-k" option to "git mv" should allow specifying multiple untracked files. Currently, multiple untracked files raise an assertion if they appear consecutively as arguments. Fix this by decrementing the loop index after removing one entry from the array of arguments. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> --- builtin-mv.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) Reported by the OP. Do we need a test case for this? It's a really trivial change. The patch is off master but builtin-mv.c hasn't change since 81dc2307d0ad87a4da2e753a9d1b5586d6456eed tags/v1.6.0-rc1~1, so I suggest this patch for maint. diff --git a/builtin-mv.c b/builtin-mv.c index 4f65b5a..bce9959 100644 --- a/builtin-mv.c +++ b/builtin-mv.c @@ -192,6 +192,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) memmove(destination + i, destination + i + 1, (argc - i) * sizeof(char *)); + i--; } } else die ("%s, source=%s, destination=%s", -- 1.6.0.6 ^ permalink raw reply related [flat|nested] 14+ messages in thread
end of thread, other threads:[~2009-01-16 13:33 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-01-14 13:20 [BUG] assertion failure in builtin-mv.c with "git mv -k" Matthieu Moy 2009-01-14 14:53 ` Michael J Gruber 2009-01-14 15:54 ` Johannes Schindelin 2009-01-14 16:04 ` Michael J Gruber 2009-01-14 16:47 ` Jeff King 2009-01-14 19:02 ` Junio C Hamano 2009-01-15 10:53 ` Michael J Gruber 2009-01-15 22:19 ` Junio C Hamano 2009-01-16 12:57 ` Matthieu Moy 2009-01-14 17:03 ` [PATCH v2 0/3] Add test cases for "git mv -k" and fix a known breakage Michael J Gruber 2009-01-14 17:03 ` [PATCH v2 1/3] add test cases for "git mv -k" Michael J Gruber 2009-01-14 17:03 ` [PATCH v2 2/3] fix handling of multiple untracked files for git mv -k Michael J Gruber 2009-01-14 17:03 ` [PATCH v2 3/3] mark fixed breakage as expect pass for "git mv -k" multiple files Michael J Gruber 2009-01-14 15:42 ` [PATCH] fix handling of multiple untracked files for git mv -k Michael J Gruber
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).