summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fcf74db)
raw | patch | inline | side by side (parent: fcf74db)
author | Olivier Marin <dkr@freesurf.fr> | |
Sat, 19 Jul 2008 16:24:46 +0000 (18:24 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 19 Jul 2008 17:41:17 +0000 (10:41 -0700) |
When hold_locked_index() is called with a relative git_dir and you are
outside the work tree, the lock file become relative to the current
directory. So when later setup_work_tree() change the current directory
it breaks lock file path and commit_locked_index() fails.
This patch move index locking code after setup_work_tree() call to make
lock file relative to the working tree as it should be and add a test
case.
Noticed by Nick Andrew.
Signed-off-by: Olivier Marin <dkr@freesurf.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
outside the work tree, the lock file become relative to the current
directory. So when later setup_work_tree() change the current directory
it breaks lock file path and commit_locked_index() fails.
This patch move index locking code after setup_work_tree() call to make
lock file relative to the working tree as it should be and add a test
case.
Noticed by Nick Andrew.
Signed-off-by: Olivier Marin <dkr@freesurf.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-rm.c | patch | blob | history | |
t/t3600-rm.sh | patch | blob | history |
diff --git a/builtin-rm.c b/builtin-rm.c
index 22c9bd1c6cf2d372e0262506cc1e21daebdf579a..abdab7f001587e819aecb5c5f7e8dcbb10a5dd48 100644 (file)
--- a/builtin-rm.c
+++ b/builtin-rm.c
git_config(git_default_config, NULL);
- newfd = hold_locked_index(&lock_file, 1);
-
- if (read_cache() < 0)
- die("index file corrupt");
-
argc = parse_options(argc, argv, builtin_rm_options, builtin_rm_usage, 0);
if (!argc)
usage_with_options(builtin_rm_usage, builtin_rm_options);
if (!index_only)
setup_work_tree();
+ newfd = hold_locked_index(&lock_file, 1);
+
+ if (read_cache() < 0)
+ die("index file corrupt");
+
pathspec = get_pathspec(prefix, argv);
seen = NULL;
for (i = 0; pathspec[i] ; i++)
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index f542f0af41989aee51f75b9844abf97943d9e33f..7893d8c40ea510595b0483432e71a74b11b24598 100755 (executable)
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
! git rm nonexistent
'
+test_expect_success 'Call "rm" from outside the work tree' '
+ mkdir repo &&
+ cd repo &&
+ git init &&
+ echo something > somefile &&
+ git add somefile &&
+ git commit -m "add a file" &&
+ (cd .. &&
+ git --git-dir=repo/.git --work-tree=repo rm somefile) &&
+ test_must_fail git ls-files --error-unmatch somefile
+'
+
test_done