Skip to content

Commit 12434ef

Browse files
pcloudsgitster
authored andcommitted
add--interactive: ignore submodule changes except HEAD
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6366dd9 commit 12434ef

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

git-add--interactive.perl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ sub list_modified {
262262
}
263263
}
264264

265-
for (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @ARGV)) {
265+
for (run_cmd_pipe(qw(git diff-files --ignore-submodules=dirty --numstat --summary --raw --), @ARGV)) {
266266
if (($add, $del, $file) =
267267
/^([-\d]+) ([-\d]+) (.*)/) {
268268
$file = unquote_path($file);

t/t3701-add-interactive.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,52 @@ test_expect_success 'add -p works even with color.ui=always' '
493493
test_cmp expect actual
494494
'
495495

496+
test_expect_success 'setup different kinds of dirty submodules' '
497+
test_create_repo for-submodules &&
498+
(
499+
cd for-submodules &&
500+
test_commit initial &&
501+
test_create_repo dirty-head &&
502+
(
503+
cd dirty-head &&
504+
test_commit initial
505+
) &&
506+
cp -R dirty-head dirty-otherwise &&
507+
cp -R dirty-head dirty-both-ways &&
508+
git add dirty-head &&
509+
git add dirty-otherwise dirty-both-ways &&
510+
git commit -m initial &&
511+
512+
cd dirty-head &&
513+
test_commit updated &&
514+
cd ../dirty-both-ways &&
515+
test_commit updated &&
516+
echo dirty >>initial &&
517+
: >untracked &&
518+
cd ../dirty-otherwise &&
519+
echo dirty >>initial &&
520+
: >untracked
521+
) &&
522+
git -C for-submodules diff-files --name-only >actual &&
523+
cat >expected <<-\EOF &&
524+
dirty-both-ways
525+
dirty-head
526+
dirty-otherwise
527+
EOF
528+
test_cmp expected actual &&
529+
git -C for-submodules diff-files --name-only --ignore-submodules=dirty >actual &&
530+
cat >expected <<-\EOF &&
531+
dirty-both-ways
532+
dirty-head
533+
EOF
534+
test_cmp expected actual
535+
'
536+
537+
test_expect_success 'status ignores dirty submodules (except HEAD)' '
538+
git -C for-submodules add -i </dev/null >output &&
539+
grep dirty-head output &&
540+
grep dirty-both-ways output &&
541+
! grep dirty-otherwise output
542+
'
543+
496544
test_done

0 commit comments

Comments
 (0)