All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH/RFC] add--interactive: ignore all internal submodule changes
@ 2018-01-10 11:06 Nguyễn Thái Ngọc Duy
  2018-01-10 19:47 ` Stefan Beller
  2018-01-13 12:10 ` [PATCH v2] add--interactive: ignore submodule changes except HEAD Nguyễn Thái Ngọc Duy
  0 siblings, 2 replies; 4+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-01-10 11:06 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

For 'add -i' and 'add -p' the only action we can take on a dirty
submodule entry (from the superproject perspective) is its SHA-1. The
content changes inside do not matter, at least until interactive add has
--recurse-submodules or something.

Ignore all dirty changes to reduce the questions 'add -i' and 'add -p'
throw at the user when submodules are dirty.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 $DAYJOB started to use submodules and this annoys me so much when I
 use 'git add -p'. I'm neither very familiar with add--interactive nor
 submodules code but this seems to work. Hopefully it's a correct
 change.

 git-add--interactive.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 28b325d754..964c3a7542 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -262,7 +262,7 @@ sub list_modified {
 		}
 	}
 
-	for (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @ARGV)) {
+	for (run_cmd_pipe(qw(git diff-files --ignore-submodules=dirty --numstat --summary --raw --), @ARGV)) {
 		if (($add, $del, $file) =
 		    /^([-\d]+)	([-\d]+)	(.*)/) {
 			$file = unquote_path($file);
-- 
2.15.1.600.g899a5f85c6


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

* Re: [PATCH/RFC] add--interactive: ignore all internal submodule changes
  2018-01-10 11:06 [PATCH/RFC] add--interactive: ignore all internal submodule changes Nguyễn Thái Ngọc Duy
@ 2018-01-10 19:47 ` Stefan Beller
  2018-01-11 11:06   ` Duy Nguyen
  2018-01-13 12:10 ` [PATCH v2] add--interactive: ignore submodule changes except HEAD Nguyễn Thái Ngọc Duy
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Beller @ 2018-01-10 19:47 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

On Wed, Jan 10, 2018 at 3:06 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> For 'add -i' and 'add -p' the only action we can take on a dirty
> submodule entry (from the superproject perspective) is its SHA-1. The
> content changes inside do not matter, at least until interactive add has
> --recurse-submodules or something.
>
> Ignore all dirty changes to reduce the questions 'add -i' and 'add -p'
> throw at the user when submodules are dirty.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  $DAYJOB started to use submodules and this annoys me so much when I
>  use 'git add -p'. I'm neither very familiar with add--interactive nor
>  submodules code but this seems to work. Hopefully it's a correct
>  change.

I would think this fixes your problem and it looks correct.

However I wonder about some subtle detail:
the "dirty" setting will ignore anything inside the submodule, and
only pay attention to the delta in gitlinks between HEAD and index.

Maybe we'd want to have a mode "dirty-except-submodule-HEAD",
which would ignore all submodule worktree changes, but if its HEAD
is different than the gitlink in the superproject index or HEAD, such that
checking out a different revision inside the submodule is not lost
when staging things in the superproject for a new commit?

>
>  git-add--interactive.perl | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 28b325d754..964c3a7542 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -262,7 +262,7 @@ sub list_modified {
>                 }
>         }
>
> -       for (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @ARGV)) {
> +       for (run_cmd_pipe(qw(git diff-files --ignore-submodules=dirty --numstat --summary --raw --), @ARGV)) {
>                 if (($add, $del, $file) =
>                     /^([-\d]+)  ([-\d]+)        (.*)/) {
>                         $file = unquote_path($file);
> --
> 2.15.1.600.g899a5f85c6
>

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

* Re: [PATCH/RFC] add--interactive: ignore all internal submodule changes
  2018-01-10 19:47 ` Stefan Beller
@ 2018-01-11 11:06   ` Duy Nguyen
  0 siblings, 0 replies; 4+ messages in thread
From: Duy Nguyen @ 2018-01-11 11:06 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git

On Thu, Jan 11, 2018 at 2:47 AM, Stefan Beller <sbeller@google.com> wrote:
> On Wed, Jan 10, 2018 at 3:06 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>> For 'add -i' and 'add -p' the only action we can take on a dirty
>> submodule entry (from the superproject perspective) is its SHA-1. The
>> content changes inside do not matter, at least until interactive add has
>> --recurse-submodules or something.
>>
>> Ignore all dirty changes to reduce the questions 'add -i' and 'add -p'
>> throw at the user when submodules are dirty.
>>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>>  $DAYJOB started to use submodules and this annoys me so much when I
>>  use 'git add -p'. I'm neither very familiar with add--interactive nor
>>  submodules code but this seems to work. Hopefully it's a correct
>>  change.
>
> I would think this fixes your problem and it looks correct.
>
> However I wonder about some subtle detail:
> the "dirty" setting will ignore anything inside the submodule, and
> only pay attention to the delta in gitlinks between HEAD and index.

Wait, why does diff-files, the command about worktree and index, look
at HEAD? Testing, testing... no I think it still works as expected

> ~/w/git/temp/z $ git ls-files  --stage foo
160000 41521690bee4b76ad108a403b79415f8591a5592 0       foo
> ~/w/git/temp/z $ git -C foo rev-parse HEAD
3bc15b2e78ec3a5c5ea27715f20adaa2669446b1
> ~/w/git/temp/z $ ../git diff --ignore-submodules=dirty foo
diff --git a/foo b/foo
index 4152169..3bc15b2 160000
--- a/foo
+++ b/foo
@@ -1 +1 @@
-Subproject commit 41521690bee4b76ad108a403b79415f8591a5592
+Subproject commit 3bc15b2e78ec3a5c5ea27715f20adaa2669446b1
> ~/w/git/temp/z $ ../git diff-files --ignore-submodules=dirty foo
:160000 160000 41521690bee4b76ad108a403b79415f8591a5592
0000000000000000000000000000000000000000 M      foo

If I reset foo/.git/HEAD back to 4152169... then diff-files
--ignore..=dirty returns empty. So I think it does check submodule's
HEAD.

> Maybe we'd want to have a mode "dirty-except-submodule-HEAD",
> which would ignore all submodule worktree changes, but if its HEAD
> is different than the gitlink in the superproject index or HEAD, such that
> checking out a different revision inside the submodule is not lost
> when staging things in the superproject for a new commit?
-- 
Duy

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

* [PATCH v2] add--interactive: ignore submodule changes except HEAD
  2018-01-10 11:06 [PATCH/RFC] add--interactive: ignore all internal submodule changes Nguyễn Thái Ngọc Duy
  2018-01-10 19:47 ` Stefan Beller
@ 2018-01-13 12:10 ` Nguyễn Thái Ngọc Duy
  1 sibling, 0 replies; 4+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-01-13 12:10 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Nguyễn Thái Ngọc Duy

For 'add -i' and 'add -p', the only action we can take on a dirty
submodule entry is update the index with a new value from its HEAD. The
content changes inside (from its own index, untracked files...) do not
matter, at least until 'git add -i' learns about launching a new
interactive add session inside a submodule.

Ignore all other submodules changes except HEAD. This reduces the number
of entries the user has to check through in 'git add -i', and the number
of 'no' they have to answer to 'git add -p' when dirty submodules are
present.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 v2 now has some tests. The commit message is rephrased a bit.

 git-add--interactive.perl  |  2 +-
 t/t3701-add-interactive.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 28b325d754..964c3a7542 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -262,7 +262,7 @@ sub list_modified {
 		}
 	}
 
-	for (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @ARGV)) {
+	for (run_cmd_pipe(qw(git diff-files --ignore-submodules=dirty --numstat --summary --raw --), @ARGV)) {
 		if (($add, $del, $file) =
 		    /^([-\d]+)	([-\d]+)	(.*)/) {
 			$file = unquote_path($file);
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index a49c12c79b..058698df6a 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -493,4 +493,52 @@ test_expect_success 'add -p works even with color.ui=always' '
 	test_cmp expect actual
 '
 
+test_expect_success 'setup different kinds of dirty submodules' '
+	test_create_repo for-submodules &&
+	(
+		cd for-submodules &&
+		test_commit initial &&
+		test_create_repo dirty-head &&
+		(
+			cd dirty-head &&
+			test_commit initial
+		) &&
+		cp -R dirty-head dirty-otherwise &&
+		cp -R dirty-head dirty-both-ways &&
+		git add dirty-head &&
+		git add dirty-otherwise dirty-both-ways &&
+		git commit -m initial &&
+
+		cd dirty-head &&
+		test_commit updated &&
+		cd ../dirty-both-ways &&
+		test_commit updated &&
+		echo dirty >>initial &&
+		: >untracked &&
+		cd ../dirty-otherwise &&
+		echo dirty >>initial &&
+		: >untracked
+	) &&
+	git -C for-submodules diff-files --name-only >actual &&
+	cat >expected <<-\EOF &&
+	dirty-both-ways
+	dirty-head
+	dirty-otherwise
+	EOF
+	test_cmp expected actual &&
+	git -C for-submodules diff-files --name-only --ignore-submodules=dirty >actual &&
+	cat >expected <<-\EOF &&
+	dirty-both-ways
+	dirty-head
+	EOF
+	test_cmp expected actual
+'
+
+test_expect_success 'status ignores dirty submodules (except HEAD)' '
+	git -C for-submodules add -i </dev/null >output &&
+	grep dirty-head output &&
+	grep dirty-both-ways output &&
+	! grep dirty-otherwise output
+'
+
 test_done
-- 
2.15.1.600.g899a5f85c6


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

end of thread, other threads:[~2018-01-13 12:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-10 11:06 [PATCH/RFC] add--interactive: ignore all internal submodule changes Nguyễn Thái Ngọc Duy
2018-01-10 19:47 ` Stefan Beller
2018-01-11 11:06   ` Duy Nguyen
2018-01-13 12:10 ` [PATCH v2] add--interactive: ignore submodule changes except HEAD Nguyễn Thái Ngọc Duy

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.