Skip to content

Commit

Permalink
Merge branch 'jc/add-refresh-unmerged' into maint
Browse files Browse the repository at this point in the history
* jc/add-refresh-unmerged:
  refresh_index: do not show unmerged path that is outside pathspec
  • Loading branch information
Junio C Hamano committed Feb 27, 2012
2 parents 8f2c099 + 3d1f148 commit 660e20f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,24 +1120,31 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
struct cache_entry *ce, *new;
int cache_errno = 0;
int changed = 0;
int filtered = 0;

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

if (pathspec &&
!match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
filtered = 1;

if (ce_stage(ce)) {
while ((i < istate->cache_nr) &&
! strcmp(istate->cache[i]->name, ce->name))
i++;
i--;
if (allow_unmerged)
continue;
show_file(unmerged_fmt, ce->name, in_porcelain, &first, header_msg);
if (!filtered)
show_file(unmerged_fmt, ce->name, in_porcelain,
&first, header_msg);
has_errors = 1;
continue;
}

if (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
if (filtered)
continue;

new = refresh_cache_ent(istate, ce, options, &cache_errno, &changed);
Expand Down
15 changes: 15 additions & 0 deletions t/t3700-add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ test_expect_success 'git add --refresh' '
test -z "`git diff-index HEAD -- foo`"
'

test_expect_success 'git add --refresh with pathspec' '
git reset --hard &&
echo >foo && echo >bar && echo >baz &&
git add foo bar baz && H=$(git rev-parse :foo) && git rm -f foo &&
echo "100644 $H 3 foo" | git update-index --index-info &&
test-chmtime -60 bar baz &&
>expect &&
git add --refresh bar >actual &&
test_cmp expect actual &&
git diff-files --name-only >actual &&
! grep bar actual&&
grep baz actual
'

test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unreadable file' '
git reset --hard &&
date >foo1 &&
Expand Down

0 comments on commit 660e20f

Please sign in to comment.