add--interactive: ignore all internal submodule changes
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.
---
$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(-)
git-add--interactive.perl +1 -1
@@ -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);
Signature · 1 line
2.15.1.600.g899a5f85c6
Quoted 8 lines · 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.
Quoted 6 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
$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?
Quoted 20 lines
git-add--interactive.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)git-add--interactive.perl +1
-2@@ -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
Quoted 16 lines · Stefan Beller
Quoted 8 lines · 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.
Quoted 6 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
$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.
Quoted 5 lines
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
Quoted 1 line
~/w/git/temp/z $ git ls-files --stage foo
160000 41521690bee4b76ad108a403b79415f8591a5592 0 foo
Quoted 1 line
~/w/git/temp/z $ git -C foo rev-parse HEAD
3bc15b2e78ec3a5c5ea27715f20adaa2669446b1
Quoted 1 line
~/w/git/temp/z $ ../git diff --ignore-submodules=dirty foo
foo +1 -1
@@ -1 +1 @@ -Subproject commit 41521690bee4b76ad108a403b79415f8591a5592 +Subproject commit 3bc15b2e78ec3a5c5ea27715f20adaa2669446b1
Quoted 1 line
~/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.
Quoted 5 lines
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?
Signature · 1 line
Duy
PATCH v2 1/1 add--interactive: ignore submodule changes except HEAD
In reply to Nguyễn Thái Ngọc DuyFor '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.
---
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(-)
git-add--interactive.perl +1 -1
@@ -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);
t/t3701-add-interactive.sh +48 -0
52 lines not on this page · raw message
Signature · 1 line
2.15.1.600.g899a5f85c6