Skip to content

Commit 660e20f

Browse files
committed
Merge branch 'jc/add-refresh-unmerged' into maint
* jc/add-refresh-unmerged: refresh_index: do not show unmerged path that is outside pathspec
2 parents 8f2c099 + 3d1f148 commit 660e20f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

read-cache.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,24 +1120,31 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
11201120
struct cache_entry *ce, *new;
11211121
int cache_errno = 0;
11221122
int changed = 0;
1123+
int filtered = 0;
11231124

11241125
ce = istate->cache[i];
11251126
if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
11261127
continue;
11271128

1129+
if (pathspec &&
1130+
!match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
1131+
filtered = 1;
1132+
11281133
if (ce_stage(ce)) {
11291134
while ((i < istate->cache_nr) &&
11301135
! strcmp(istate->cache[i]->name, ce->name))
11311136
i++;
11321137
i--;
11331138
if (allow_unmerged)
11341139
continue;
1135-
show_file(unmerged_fmt, ce->name, in_porcelain, &first, header_msg);
1140+
if (!filtered)
1141+
show_file(unmerged_fmt, ce->name, in_porcelain,
1142+
&first, header_msg);
11361143
has_errors = 1;
11371144
continue;
11381145
}
11391146

1140-
if (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
1147+
if (filtered)
11411148
continue;
11421149

11431150
new = refresh_cache_ent(istate, ce, options, &cache_errno, &changed);

t/t3700-add.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ test_expect_success 'git add --refresh' '
179179
test -z "`git diff-index HEAD -- foo`"
180180
'
181181

182+
test_expect_success 'git add --refresh with pathspec' '
183+
git reset --hard &&
184+
echo >foo && echo >bar && echo >baz &&
185+
git add foo bar baz && H=$(git rev-parse :foo) && git rm -f foo &&
186+
echo "100644 $H 3 foo" | git update-index --index-info &&
187+
test-chmtime -60 bar baz &&
188+
>expect &&
189+
git add --refresh bar >actual &&
190+
test_cmp expect actual &&
191+
192+
git diff-files --name-only >actual &&
193+
! grep bar actual&&
194+
grep baz actual
195+
'
196+
182197
test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unreadable file' '
183198
git reset --hard &&
184199
date >foo1 &&

0 commit comments

Comments
 (0)