Skip to content

Commit cced48a

Browse files
dschospearce
authored andcommitted
git rm: refresh index before up-to-date check
Since "git rm" is supposed to be porcelain, we should convince it to be user friendly by refreshing the index itself. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent daf6c2e commit cced48a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

builtin-rm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
137137

138138
if (read_cache() < 0)
139139
die("index file corrupt");
140+
refresh_cache(REFRESH_QUIET);
140141

141142
pathspec = get_pathspec(prefix, argv);
142143
seen = NULL;

t/t3600-rm.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,23 @@ test_expect_success 'Remove nonexistent file returns nonzero exit status' '
219219

220220
test_expect_success 'Call "rm" from outside the work tree' '
221221
mkdir repo &&
222-
cd repo &&
223-
git init &&
224-
echo something > somefile &&
225-
git add somefile &&
226-
git commit -m "add a file" &&
227-
(cd .. &&
228-
git --git-dir=repo/.git --work-tree=repo rm somefile) &&
229-
test_must_fail git ls-files --error-unmatch somefile
222+
(cd repo &&
223+
git init &&
224+
echo something > somefile &&
225+
git add somefile &&
226+
git commit -m "add a file" &&
227+
(cd .. &&
228+
git --git-dir=repo/.git --work-tree=repo rm somefile) &&
229+
test_must_fail git ls-files --error-unmatch somefile)
230+
'
231+
232+
test_expect_success 'refresh index before checking if it is up-to-date' '
233+
234+
git reset --hard &&
235+
test-chmtime -86400 frotz/nitfol &&
236+
git rm frotz/nitfol &&
237+
test ! -f frotz/nitfol
238+
230239
'
231240

232241
test_done

0 commit comments

Comments
 (0)