From aca085e577688108a2480b96a2f7077424a74e4d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 3 Dec 2006 20:42:47 +0100 Subject: git-mv: search more precisely for source directory in index A move of a directory should find the entries in the index by searching for the name _including_ the slash. Otherwise, the directory can be shadowed by a file when it matches the prefix and is lexicographically smaller, e.g. "ab.c" shadows "ab/". Noticed by Sergey Vlasov. [jc: added Sergey's original reproduction recipe as a test case at the end of t7001.] Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/builtin-mv.c b/builtin-mv.c index 54dd3bf..d14a4a7 100644 --- a/builtin-mv.c +++ b/builtin-mv.c @@ -146,21 +146,24 @@ int cmd_mv(int argc, const char **argv, const char *prefix) && lstat(dst, &st) == 0) bad = "cannot move directory over file"; else if (src_is_dir) { + const char *src_w_slash = add_slash(src); + int len_w_slash = length + 1; int first, last; modes[i] = WORKING_DIRECTORY; - first = cache_name_pos(src, length); + first = cache_name_pos(src_w_slash, len_w_slash); if (first >= 0) - die ("Huh? %s/ is in index?", src); + die ("Huh? %.*s is in index?", + len_w_slash, src_w_slash); first = -1 - first; for (last = first; last < active_nr; last++) { const char *path = active_cache[last]->name; - if (strncmp(path, src, length) - || path[length] != '/') + if (strncmp(path, src_w_slash, len_w_slash)) break; } + free((char *)src_w_slash); if (last - first < 1) bad = "source directory is empty"; diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 23a1eff..2f4ff82 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -105,4 +105,17 @@ test_expect_success "Michael Cassar's test case" ' } ' +rm -fr papers partA path? + +test_expect_success "Sergey Vlasov's test case" ' + rm -fr .git && + git init-db && + mkdir ab && + date >ab.c && + date >ab/d && + git add ab.c ab && + git commit -m 'initial' && + git mv ab a +' + test_done -- cgit v0.10.2-6-g49f6 From 562cefbdbfaeb92f91c961c67960a93a7772220c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 4 Dec 2006 14:24:12 -0800 Subject: receive-pack: do not insist on fast-forward outside refs/heads/ Especially refs/tags/ hierarchy should match what git-fetch checks. Signed-off-by: Junio C Hamano diff --git a/receive-pack.c b/receive-pack.c index d56898c..f189151 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -118,7 +118,8 @@ static int update(struct command *cmd) return error("unpack should have generated %s, " "but I can't find it!", new_hex); } - if (deny_non_fast_forwards && !is_null_sha1(old_sha1)) { + if (deny_non_fast_forwards && !is_null_sha1(old_sha1) && + !strncmp(name, "refs/heads/", 11)) { struct commit *old_commit, *new_commit; struct commit_list *bases, *ent; -- cgit v0.10.2-6-g49f6