Skip to content

Commit ba988a8

Browse files
author
Junio C Hamano
committed
Merge branch 'maint'
* maint: receive-pack: do not insist on fast-forward outside refs/heads/ git-mv: search more precisely for source directory in index Conflicts: receive-pack.c
2 parents 4cd7535 + 562cefb commit ba988a8

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

builtin-mv.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,24 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
146146
&& lstat(dst, &st) == 0)
147147
bad = "cannot move directory over file";
148148
else if (src_is_dir) {
149+
const char *src_w_slash = add_slash(src);
150+
int len_w_slash = length + 1;
149151
int first, last;
150152

151153
modes[i] = WORKING_DIRECTORY;
152154

153-
first = cache_name_pos(src, length);
155+
first = cache_name_pos(src_w_slash, len_w_slash);
154156
if (first >= 0)
155-
die ("Huh? %s/ is in index?", src);
157+
die ("Huh? %.*s is in index?",
158+
len_w_slash, src_w_slash);
156159

157160
first = -1 - first;
158161
for (last = first; last < active_nr; last++) {
159162
const char *path = active_cache[last]->name;
160-
if (strncmp(path, src, length)
161-
|| path[length] != '/')
163+
if (strncmp(path, src_w_slash, len_w_slash))
162164
break;
163165
}
166+
free((char *)src_w_slash);
164167

165168
if (last - first < 1)
166169
bad = "source directory is empty";

receive-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ static int update(struct command *cmd)
120120
"but I can't find it!", new_hex);
121121
}
122122
if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
123-
!is_null_sha1(old_sha1)) {
123+
!is_null_sha1(old_sha1) &&
124+
!strncmp(name, "refs/heads/", 11)) {
124125
struct commit *old_commit, *new_commit;
125126
struct commit_list *bases, *ent;
126127

t/t7001-mv.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,17 @@ test_expect_success "Michael Cassar's test case" '
105105
}
106106
'
107107

108+
rm -fr papers partA path?
109+
110+
test_expect_success "Sergey Vlasov's test case" '
111+
rm -fr .git &&
112+
git init-db &&
113+
mkdir ab &&
114+
date >ab.c &&
115+
date >ab/d &&
116+
git add ab.c ab &&
117+
git commit -m 'initial' &&
118+
git mv ab a
119+
'
120+
108121
test_done

0 commit comments

Comments
 (0)