git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Merge: "git rm bla": "bla: needs merge", but still removes file "bla"
@ 2019-07-17  7:58 Ulrich Windl
  2019-07-17 16:44 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Ulrich Windl @ 2019-07-17  7:58 UTC (permalink / raw)
  To: git

Hi!

I just had "an interesting case" for a merge with conflicts:
The merge re-introduced a file that had been renamed (say old one is "bla", and the new one is "foo").
After merging the changes from bla into foo, I added foo, trying to remove bla:
> git add foo
> git rm bla
bla: needs merge
rm 'bla'

The interesting part is that the file was still removed, while claiming "needs merge" before:
> git rm bla
fatal: pathspec 'bla' did not match any files

(git-2.12.3-27.14.1.x86_64 from SLES12 SP4)

Regards,
Ulrich



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Merge: "git rm bla": "bla: needs merge", but still removes file "bla"
  2019-07-17  7:58 Merge: "git rm bla": "bla: needs merge", but still removes file "bla" Ulrich Windl
@ 2019-07-17 16:44 ` Junio C Hamano
  2019-07-17 20:38   ` [PATCH] rm: resolving by removal is not a warning-worthy event Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2019-07-17 16:44 UTC (permalink / raw)
  To: Ulrich Windl; +Cc: git

"Ulrich Windl" <Ulrich.Windl@rz.uni-regensburg.de> writes:

> I just had "an interesting case" for a merge with conflicts:
> The merge re-introduced a file that had been renamed (say old one is "bla", and the new one is "foo").
> After merging the changes from bla into foo, I added foo, trying to remove bla:
>> git add foo
>> git rm bla
> bla: needs merge
> rm 'bla'

Yeah, I think I've known about this for a long time.  We have an
internal call to "update-index --refresh" before starting to remove,
because we need to know which path is up-to-date wrt the index, and
the machinery for refreshing the index by default gives the "needs
merge" message.  We never bothered to squelch it.

Perhaps this one-liner would be a sufficient fix.



 builtin/rm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/rm.c b/builtin/rm.c
index 2eacda42b4..19ce95a901 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -273,7 +273,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 	parse_pathspec(&pathspec, 0,
 		       PATHSPEC_PREFER_CWD,
 		       prefix, argv);
-	refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
+	refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);
 
 	seen = xcalloc(pathspec.nr, 1);
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] rm: resolving by removal is not a warning-worthy event
  2019-07-17 16:44 ` Junio C Hamano
@ 2019-07-17 20:38   ` Junio C Hamano
  2019-07-18 20:26     ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2019-07-17 20:38 UTC (permalink / raw)
  To: git; +Cc: Ulrich Windl

When resolving a conflict on a path in favor of removing it, using
"git rm" on it is the standard way to do so.  The user however is
greeted with a "needs merge" message during that operation:

	$ git merge side-branch
	$ edit conflicted-path-1
	$ git add conflicted-path-1
	$ git rm conflicted-path-2
	conflicted-path-2: needs merge
	rm 'conflicted-path-2'

The removal by "git rm" does get performed, but an uninitiated user
may find it confusing, "needs merge? so I need to resolve conflict
before being able to remove it???"

The message is coming from "update-index --refresh" that is called
internally to make sure "git rm" knows which paths are clean and
which paths are dirty, in order to prevent removal of paths modified
relative to the index without the "-f" option.  We somehow ended up
not squelching this message which seeped through to the UI surface.

Use the same mechanism used by "git commit", "git describe", etc. to
squelch the message.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/rm.c  |  2 +-
 t/t3600-rm.sh | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/builtin/rm.c b/builtin/rm.c
index 65b448ef8e..b63c86ae92 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -272,7 +272,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 	parse_pathspec(&pathspec, 0,
 		       PATHSPEC_PREFER_CWD,
 		       prefix, argv);
-	refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
+	refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);
 
 	seen = xcalloc(pathspec.nr, 1);
 
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index b8fbdefcdc..5aae78ccc4 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -251,6 +251,19 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
 	test_path_is_missing .git/index.lock
 '
 
+test_expect_success 'Resolving by removal is not a warning-worthy event' '
+	git reset -q --hard &&
+	test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
+	qfwfq=$(echo qfwfq | git hash-object -w --stdin) &&
+	for stage in 1 2 3
+	do
+		echo "100644 $qfwfq $stage	qfwfq"
+	done | git update-index --index-info &&
+	git rm qfwfq >msg &&
+	test_i18ngrep ! "needs merge" msg &&
+	test_must_fail git ls-files -s --error-unmatch qfwfq
+'
+
 test_expect_success 'rm removes subdirectories recursively' '
 	mkdir -p dir/subdir/subsubdir &&
 	echo content >dir/subdir/subsubdir/file &&
-- 
2.22.0-653-g37fc7794bc


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] rm: resolving by removal is not a warning-worthy event
  2019-07-17 20:38   ` [PATCH] rm: resolving by removal is not a warning-worthy event Junio C Hamano
@ 2019-07-18 20:26     ` Jeff King
  2019-07-18 21:07       ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff King @ 2019-07-18 20:26 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Ulrich Windl

On Wed, Jul 17, 2019 at 01:38:35PM -0700, Junio C Hamano wrote:

> When resolving a conflict on a path in favor of removing it, using
> "git rm" on it is the standard way to do so.  The user however is
> greeted with a "needs merge" message during that operation:
> 
> 	$ git merge side-branch
> 	$ edit conflicted-path-1
> 	$ git add conflicted-path-1
> 	$ git rm conflicted-path-2
> 	conflicted-path-2: needs merge
> 	rm 'conflicted-path-2'
> 
> The removal by "git rm" does get performed, but an uninitiated user
> may find it confusing, "needs merge? so I need to resolve conflict
> before being able to remove it???"
> 
> The message is coming from "update-index --refresh" that is called
> internally to make sure "git rm" knows which paths are clean and
> which paths are dirty, in order to prevent removal of paths modified
> relative to the index without the "-f" option.  We somehow ended up
> not squelching this message which seeped through to the UI surface.
> 
> Use the same mechanism used by "git commit", "git describe", etc. to
> squelch the message.

Nicely explained, and the patch makes sense.

> +test_expect_success 'Resolving by removal is not a warning-worthy event' '
> +	git reset -q --hard &&
> +	test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
> +	qfwfq=$(echo qfwfq | git hash-object -w --stdin) &&

I'd have called this "$blob" for my own sanity in typing later lines,
but OK. :)

> +	do
> +		echo "100644 $qfwfq $stage	qfwfq"
> +	done | git update-index --index-info &&
> +	git rm qfwfq >msg &&
> +	test_i18ngrep ! "needs merge" msg &&

Should we capture stderr from "git rm", too, to cover all bases?

-Peff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rm: resolving by removal is not a warning-worthy event
  2019-07-18 20:26     ` Jeff King
@ 2019-07-18 21:07       ` Junio C Hamano
  2019-07-18 21:43         ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2019-07-18 21:07 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Ulrich Windl

Jeff King <peff@peff.net> writes:

>> +test_expect_success 'Resolving by removal is not a warning-worthy event' '
>> +	git reset -q --hard &&
>> +	test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
>> +	qfwfq=$(echo qfwfq | git hash-object -w --stdin) &&
>
> I'd have called this "$blob" for my own sanity in typing later lines,
> but OK. :)

OK, I can change that easily ;-)

>> +	do
>> +		echo "100644 $qfwfq $stage	qfwfq"
>> +	done | git update-index --index-info &&
>> +	git rm qfwfq >msg &&
>> +	test_i18ngrep ! "needs merge" msg &&
>
> Should we capture stderr from "git rm", too, to cover all bases?

Do you mean

	git rm blob >msg 2>&1

because we could later change our mind and send "needs merge"
message to the standard error stream?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rm: resolving by removal is not a warning-worthy event
  2019-07-18 21:07       ` Junio C Hamano
@ 2019-07-18 21:43         ` Jeff King
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2019-07-18 21:43 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Ulrich Windl

On Thu, Jul 18, 2019 at 02:07:23PM -0700, Junio C Hamano wrote:

> >> +	git rm qfwfq >msg &&
> >> +	test_i18ngrep ! "needs merge" msg &&
> >
> > Should we capture stderr from "git rm", too, to cover all bases?
> 
> Do you mean
> 
> 	git rm blob >msg 2>&1
> 
> because we could later change our mind and send "needs merge"
> message to the standard error stream?

Yes, exactly.

-Peff

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-07-18 21:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17  7:58 Merge: "git rm bla": "bla: needs merge", but still removes file "bla" Ulrich Windl
2019-07-17 16:44 ` Junio C Hamano
2019-07-17 20:38   ` [PATCH] rm: resolving by removal is not a warning-worthy event Junio C Hamano
2019-07-18 20:26     ` Jeff King
2019-07-18 21:07       ` Junio C Hamano
2019-07-18 21:43         ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).