@matheusbsbs / matheus-bagliano / commits / ea08a6fd19
Fork 0

Actually allow TAG_FIXUP branches in fast-import

Michael Haggerty <mhagger@alum.mit.edu> noticed while debugging a Git backend for cvs2svn that fast-import was barfing when he tried to use "TAG_FIXUP" as a branch name for temporary work needed to cleanup the tree prior to creating an annotated tag object. The reason we were rejecting the branch name was check_ref_format() returns -2 when there are less than 2 '/' characters in the input name. TAG_FIXUP has 0 '/' characters, but is technically just as valid of a ref as HEAD and MERGE_HEAD, so we really should permit it (and any other similar looking name) during import. New test cases have been added to make sure we still detect very wrong branch names (e.g. containing [ or starting with .) and yet still permit reasonable names (e.g. TAG_FIXUP). Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Aug 2, 2007 at 23:37 UTC ea08a6fd194991f9d800e4cac5ae55fdb02dd235
2 files changed +52 -1
fast-import.c
+5 -1
@@ -524,8 +524,12 @@ static struct branch *new_branch(const char *name)
524
525 if (b)
526 die("Invalid attempt to create duplicate branch: %s", name);
527 - if (check_ref_format(name))
527 + switch (check_ref_format(name)) {
528 + case 0: break; /* its valid */
529 + case -2: break; /* valid, but too few '/', allow anyway */
530 + default:
531 die("Branch name doesn't conform to GIT standards: %s", name);
532 + }
533
534 b = pool_calloc(1, sizeof(struct branch));
535 b->name = pool_strdup(name);
t/t9300-fast-import.sh
+47
@@ -170,6 +170,53 @@ test_expect_failure \
170 'git-fast-import <input'
171 rm -f .git/objects/pack_* .git/objects/index_*
172
173 +cat >input <<INPUT_END
174 +commit .badbranchname
175 +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
176 +data <<COMMIT
177 +corrupt
178 +COMMIT
179 +
180 +from refs/heads/master
181 +
182 +INPUT_END
183 +test_expect_failure \
184 + 'B: fail on invalid branch name ".badbranchname"' \
185 + 'git-fast-import <input'
186 +rm -f .git/objects/pack_* .git/objects/index_*
187 +
188 +cat >input <<INPUT_END
189 +commit bad[branch]name
190 +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
191 +data <<COMMIT
192 +corrupt
193 +COMMIT
194 +
195 +from refs/heads/master
196 +
197 +INPUT_END
198 +test_expect_failure \
199 + 'B: fail on invalid branch name "bad[branch]name"' \
200 + 'git-fast-import <input'
201 +rm -f .git/objects/pack_* .git/objects/index_*
202 +
203 +cat >input <<INPUT_END
204 +commit TEMP_TAG
205 +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
206 +data <<COMMIT
207 +tag base
208 +COMMIT
209 +
210 +from refs/heads/master
211 +
212 +INPUT_END
213 +test_expect_success \
214 + 'B: accept branch name "TEMP_TAG"' \
215 + 'git-fast-import <input &&
216 + test -f .git/TEMP_TAG &&
217 + test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
218 +rm -f .git/TEMP_TAG
219 +
220 ###
221 ### series C
222 ###