Skip to content

Commit

Permalink
do not overwrite files marked "assume unchanged"
Browse files Browse the repository at this point in the history
A merge will fail gracefully if it needs to update files marked
"assume unchanged", but other similar commands will not. In
particular, checkout and rebase will silently overwrite changes to
such files.

This is a regression introduced in commit 1dcafcc (verify_uptodate():
add ce_uptodate(ce) test), which avoids lstat's during a merge, if the
index entry is up-to-date. If the CE_VALID flag is set, however, we
cannot trust CE_UPTODATE.

Signed-off-by: Clemens Buchacher <drizzd@aon.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Clemens Buchacher authored and Junio C Hamano committed May 1, 2010
1 parent e92e9cd commit aecda37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions t/t2106-update-index-assume-unchanged.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

test_description='git update-index --assume-unchanged test.
'

. ./test-lib.sh

test_expect_success 'setup' \
': >file &&
git add file &&
git commit -m initial &&
git branch other &&
echo upstream >file &&
git add file &&
git commit -m upstream'

test_expect_success 'do not switch branches with dirty file' \
'git reset --hard &&
git checkout other &&
echo dirt >file &&
git update-index --assume-unchanged file &&
test_must_fail git checkout master'

test_done
2 changes: 1 addition & 1 deletion unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ static int verify_uptodate_1(struct cache_entry *ce,
{
struct stat st;

if (o->index_only || (!ce_skip_worktree(ce) && (o->reset || ce_uptodate(ce))))
if (o->index_only || (!((ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) && (o->reset || ce_uptodate(ce))))
return 0;

if (!lstat(ce->name, &st)) {
Expand Down

0 comments on commit aecda37

Please sign in to comment.