All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.
@ 2016-09-12 11:24 Mikhail Filippov
  0 siblings, 0 replies; 5+ messages in thread
From: Mikhail Filippov @ 2016-09-12 11:24 UTC (permalink / raw)
  To: git; +Cc: Mikhail Filippov

It's a very unexpected behaviour when a user sees a deleted file after a merge with enabled sparse-checkout. Moreover, when the user resolves merge conflicts and commits the changes with the command "git commit -am xxx", a repository can be broken because all the moved files will be deleted. Finally, it's really hard to find a user who deleted these files because "git log file" doesn't show any merge commits by default. I'm not sure that my fix is correct but I checked all tests and I didn't find a better way to prevent files deleting.
---
 merge-recursive.c                    |  9 +++++---
 t/t6042-merge-rename-corner-cases.sh | 41 ++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index e349126..25dc701 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1724,9 +1724,12 @@ static int merge_content(struct merge_options *o,
 		 */
 		path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
 		if (!path_renamed_outside_HEAD) {
-			add_cacheinfo(o, mfi.mode, &mfi.oid, path,
-				      0, (!o->call_depth), 0);
-			return mfi.clean;
+			struct stat st;
+			if (lstat(path, &st) == 0) {
+				add_cacheinfo(o, mfi.mode, &mfi.oid, path,
+					      0, (!o->call_depth), 0);
+				return mfi.clean;
+			}
 		}
 	} else
 		output(o, 2, _("Auto-merging %s"), path);
diff --git a/t/t6042-merge-rename-corner-cases.sh b/t/t6042-merge-rename-corner-cases.sh
index 411550d..5d84418 100755
--- a/t/t6042-merge-rename-corner-cases.sh
+++ b/t/t6042-merge-rename-corner-cases.sh
@@ -575,4 +575,45 @@ test_expect_success 'rename/rename/add-dest merge still knows about conflicting
 	test ! -f c
 '
 
+test_expect_success 'move file/sparse-checkout/merge should not delete moved file' '
+	git rm -rf . &&
+	git clean -fdqx &&
+	rm -rf .git &&
+	git init &&
+
+	echo output >.gitignore &&
+	echo .gitignore >>.gitignore &&
+
+	echo b1 >b1 &&
+	git add b1 &&
+	git commit -m b1 &&
+
+	mkdir excluded &&
+	echo problem >excluded/to-be-moved.txt &&
+	git add excluded/to-be-moved.txt &&
+	git commit -m to-be-moved &&
+	git tag split_point &&
+
+	echo b2 >b2 &&
+	git add b2 &&
+	git commit -m b2 &&
+	git tag b2 &&
+
+	git reset --hard split_point &&
+
+	git mv excluded/to-be-moved.txt excluded/moved.txt &&
+	git commit -m move &&
+	git tag b1 &&
+
+	git config core.sparsecheckout true &&
+	echo "/*" >.git/info/sparse-checkout &&
+	echo "!excluded/" >>.git/info/sparse-checkout &&
+	git read-tree -mu HEAD &&
+
+	git merge -m merge b2 &&
+
+	git status >output &&
+	test_i18ngrep "nothing to commit" output
+'
+
 test_done
-- 
2.7.4 (Apple Git-66)


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

* Re: [PATCH] Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.
  2016-09-11 23:24 ` Junio C Hamano
  2016-09-12  8:38   ` Mikhail Filippov
@ 2016-09-12 11:07   ` Mikhail Filippov
  1 sibling, 0 replies; 5+ messages in thread
From: Mikhail Filippov @ 2016-09-12 11:07 UTC (permalink / raw)
  To: git

>>  +test_expect_success 'move file/sparse-checkout/merge should not delete moved file' '
>>  + git rm -rf . &&
>>  + git clean -fdqx &&
>>  + rm -rf .git &&
>>  + git init &&
>
> Yuck. This is inherited from existing tests but I think they need
> to be cleaned up. It is not your fault, and it is not in the scope
> of this change.
It's part need for cleanup repository from the previous case.

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

* Re: [PATCH] Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.
  2016-09-11 23:24 ` Junio C Hamano
@ 2016-09-12  8:38   ` Mikhail Filippov
  2016-09-12 11:07   ` Mikhail Filippov
  1 sibling, 0 replies; 5+ messages in thread
From: Mikhail Filippov @ 2016-09-12  8:38 UTC (permalink / raw)
  To: git

It's a very unexpected behaviour when a user sees a deleted file after a merge with enabled sparse-checkout. Moreover, when the user resolves merge conflicts and commits the changes with the command "git commit -am xxx", a repository can be broken because all the moved files will be deleted. Finally, it's really hard to find a user who deleted these files because "git log file" doesn't show any merge commits by default. I'm not sure that my fix is correct but I checked all tests and I didn't find a better way to prevent files deleting.

12.09.2016, 02:24, "Junio C Hamano" <gitster@pobox.com>:
>    Mikhail Filippov <mikhail@filippov.me> writes:
>
>>     ---
>
>    You'd need a lot more explanation on why this is needed
>    (i.e. without it what behaviour you would get, and why that
>    behaviour is wrong).
>
>>      merge-recursive.c | 9 +++++---
>>      t/t6042-merge-rename-corner-cases.sh | 42 ++++++++++++++++++++++++++++++++++++
>>      2 files changed, 48 insertions(+), 3 deletions(-)
>>
>>     diff --git a/merge-recursive.c b/merge-recursive.c
>>     index e349126..25dc701 100644
>>     --- a/merge-recursive.c
>>     +++ b/merge-recursive.c
>>     @@ -1724,9 +1724,12 @@ static int merge_content(struct merge_options *o,
>>                       */
>>                      path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
>>                      if (!path_renamed_outside_HEAD) {
>>     - add_cacheinfo(o, mfi.mode, &mfi.oid, path,
>>     - 0, (!o->call_depth), 0);
>>     - return mfi.clean;
>>     + struct stat st;
>>     + if (lstat(path, &st) == 0) {
>>     + add_cacheinfo(o, mfi.mode, &mfi.oid, path,
>>     + 0, (!o->call_depth), 0);
>>     + return mfi.clean;
>>     + }
>
>    I cannot guess what you are trying to achieve without explanation in
>    the proposed log message, but I can say that this unconditional
>    checking of a working tree file cannot be correct (there may or may
>    not be other things that are wrong with this change, which cannot be
>    judged without more information).
>
>    Imagine your o->call_depth is not zero, i.e. we are making a virtual
>    common ancestor with this merge, in which case any of the three
>    trees involved may have nothing to do with the current working tree
>    files.
>
>>     +test_expect_success 'move file/sparse-checkout/merge should not delete moved file' '
>>     + git rm -rf . &&
>>     + git clean -fdqx &&
>>     + rm -rf .git &&
>>     + git init &&
>
>    Yuck. This is inherited from existing tests but I think they need
>    to be cleaned up. It is not your fault, and it is not in the scope
>    of this change.
>
>>     + git status >output &&
>>     + cp output /tmp/a &&
>
>    Huh?
>
>>     + test_i18ngrep "nothing to commit" output
>>     +'
>>     +
>>      test_done




-- 
Mikhail Filippov 
Software Developer
JetBrains
http://jetbrains.com
“The Drive To Develop"

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

* Re: [PATCH] Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.
  2016-09-11 20:25 Mikhail Filippov
@ 2016-09-11 23:24 ` Junio C Hamano
  2016-09-12  8:38   ` Mikhail Filippov
  2016-09-12 11:07   ` Mikhail Filippov
  0 siblings, 2 replies; 5+ messages in thread
From: Junio C Hamano @ 2016-09-11 23:24 UTC (permalink / raw)
  To: Mikhail Filippov; +Cc: git

Mikhail Filippov <mikhail@filippov.me> writes:

> ---

You'd need a lot more explanation on why this is needed
(i.e. without it what behaviour you would get, and why that
behaviour is wrong).

>  merge-recursive.c                    |  9 +++++---
>  t/t6042-merge-rename-corner-cases.sh | 42 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 48 insertions(+), 3 deletions(-)
>
> diff --git a/merge-recursive.c b/merge-recursive.c
> index e349126..25dc701 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -1724,9 +1724,12 @@ static int merge_content(struct merge_options *o,
>  		 */
>  		path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
>  		if (!path_renamed_outside_HEAD) {
> -			add_cacheinfo(o, mfi.mode, &mfi.oid, path,
> -				      0, (!o->call_depth), 0);
> -			return mfi.clean;
> +			struct stat st;
> +			if (lstat(path, &st) == 0) {
> +				add_cacheinfo(o, mfi.mode, &mfi.oid, path,
> +					      0, (!o->call_depth), 0);
> +				return mfi.clean;
> +			}

I cannot guess what you are trying to achieve without explanation in
the proposed log message, but I can say that this unconditional
checking of a working tree file cannot be correct (there may or may
not be other things that are wrong with this change, which cannot be
judged without more information).

Imagine your o->call_depth is not zero, i.e. we are making a virtual
common ancestor with this merge, in which case any of the three
trees involved may have nothing to do with the current working tree
files.

> +test_expect_success 'move file/sparse-checkout/merge should not delete moved file' '
> +	git rm -rf . &&
> +	git clean -fdqx &&
> +	rm -rf .git &&
> +	git init &&

Yuck.  This is inherited from existing tests but I think they need
to be cleaned up.  It is not your fault, and it is not in the scope
of this change.

> +	git status >output &&
> +	cp output /tmp/a &&

Huh?

> +	test_i18ngrep "nothing to commit" output
> +'
> +
>  test_done

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

* [PATCH] Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.
@ 2016-09-11 20:25 Mikhail Filippov
  2016-09-11 23:24 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Mikhail Filippov @ 2016-09-11 20:25 UTC (permalink / raw)
  To: git; +Cc: Mikhail Filippov

---
 merge-recursive.c                    |  9 +++++---
 t/t6042-merge-rename-corner-cases.sh | 42 ++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index e349126..25dc701 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1724,9 +1724,12 @@ static int merge_content(struct merge_options *o,
 		 */
 		path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
 		if (!path_renamed_outside_HEAD) {
-			add_cacheinfo(o, mfi.mode, &mfi.oid, path,
-				      0, (!o->call_depth), 0);
-			return mfi.clean;
+			struct stat st;
+			if (lstat(path, &st) == 0) {
+				add_cacheinfo(o, mfi.mode, &mfi.oid, path,
+					      0, (!o->call_depth), 0);
+				return mfi.clean;
+			}
 		}
 	} else
 		output(o, 2, _("Auto-merging %s"), path);
diff --git a/t/t6042-merge-rename-corner-cases.sh b/t/t6042-merge-rename-corner-cases.sh
index 411550d..2073e49 100755
--- a/t/t6042-merge-rename-corner-cases.sh
+++ b/t/t6042-merge-rename-corner-cases.sh
@@ -575,4 +575,46 @@ test_expect_success 'rename/rename/add-dest merge still knows about conflicting
 	test ! -f c
 '
 
+test_expect_success 'move file/sparse-checkout/merge should not delete moved file' '
+	git rm -rf . &&
+	git clean -fdqx &&
+	rm -rf .git &&
+	git init &&
+
+	echo output >.gitignore &&
+	echo .gitignore >>.gitignore &&
+
+	echo b1 >b1 &&
+	git add b1 &&
+	git commit -m b1 &&
+
+	mkdir excluded &&
+	echo problem >excluded/to-be-moved.txt &&
+	git add excluded/to-be-moved.txt &&
+	git commit -m to-be-moved &&
+	git tag split_point &&
+
+	echo b2 >b2 &&
+	git add b2 &&
+	git commit -m b2 &&
+	git tag b2 &&
+
+	git reset --hard split_point &&
+
+	git mv excluded/to-be-moved.txt excluded/moved.txt &&
+	git commit -m move &&
+	git tag b1 &&
+
+	git config core.sparsecheckout true &&
+	echo "/*" >.git/info/sparse-checkout &&
+	echo "!excluded/" >>.git/info/sparse-checkout &&
+	git read-tree -mu HEAD &&
+
+	git merge -m merge b2 &&
+
+	git status >output &&
+	cp output /tmp/a &&
+	test_i18ngrep "nothing to commit" output
+'
+
 test_done
-- 
2.7.4 (Apple Git-66)


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

end of thread, other threads:[~2016-09-12 11:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-12 11:24 [PATCH] Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout Mikhail Filippov
  -- strict thread matches above, loose matches on Subject: below --
2016-09-11 20:25 Mikhail Filippov
2016-09-11 23:24 ` Junio C Hamano
2016-09-12  8:38   ` Mikhail Filippov
2016-09-12 11:07   ` Mikhail Filippov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.