Do not allow ".lock" at the end of any refname component
Allowing any refname component to end with ".lock" is looking for trouble; for example, $ git br foo.lock/bar $ git br foo fatal: Unable to create '[...]/.git/refs/heads/foo.lock': File exists. Therefore, do not allow any refname component to end with ".lock". Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Sep 15, 2011 at 23:10 UTC
7e9d2fe96060957d90870d2fac9b85608423e277
3 files changed
+7
-9
Documentation/git-check-ref-format.txt
+1
-3
@@ -28,7 +28,7 @@ git imposes the following rules on how references are named:
28
29
. They can include slash `/` for hierarchical (directory)
30
grouping, but no slash-separated component can begin with a
31
- dot `.`.
31
+ dot `.` or end with the sequence `.lock`.
32
33
. They must contain at least one `/`. This enforces the presence of a
34
category like `heads/`, `tags/` etc. but the actual names are not
@@ -47,8 +47,6 @@ git imposes the following rules on how references are named:
47
48
. They cannot end with a slash `/` nor a dot `.`.
49
50
-. They cannot end with the sequence `.lock`.
51
-
50
. They cannot contain a sequence `@{`.
51
52
. They cannot contain a `\`.
refs.c
+2
-2
@@ -898,6 +898,8 @@ static int check_refname_component(const char *ref)
898
return -1; /* Component has zero length. */
899
if (ref[0] == '.')
900
return -1; /* Component starts with '.'. */
901
+ if (cp - ref >= 5 && !memcmp(cp - 5, ".lock", 5))
902
+ return -1; /* Refname ends with ".lock". */
903
return cp - ref;
904
}
905
@@ -931,8 +933,6 @@ int check_refname_format(const char *ref, int flags)
933
934
if (ref[component_len - 1] == '.')
935
return -1; /* Refname ends with '.'. */
934
- if (component_len >= 5 && !memcmp(&ref[component_len - 5], ".lock", 5))
935
- return -1; /* Refname ends with ".lock". */
936
if (!(flags & REFNAME_ALLOW_ONELEVEL) && component_count < 2)
937
return -1; /* Refname has only one component. */
938
return 0;
t/t1402-check-ref-format.sh
+4
-4
@@ -43,8 +43,8 @@ invalid_ref 'heads/foo?bar'
43
valid_ref 'foo./bar'
44
invalid_ref 'heads/foo.lock'
45
invalid_ref 'heads///foo.lock'
46
-valid_ref 'foo.lock/bar'
47
-valid_ref 'foo.lock///bar'
46
+invalid_ref 'foo.lock/bar'
47
+invalid_ref 'foo.lock///bar'
48
valid_ref 'heads/foo@bar'
49
invalid_ref 'heads/v@{ation'
50
invalid_ref 'heads/foo\bar'
@@ -160,7 +160,7 @@ invalid_ref_normalized 'heads/./foo'
160
invalid_ref_normalized 'heads\foo'
161
invalid_ref_normalized 'heads/foo.lock'
162
invalid_ref_normalized 'heads///foo.lock'
163
-valid_ref_normalized 'foo.lock/bar' 'foo.lock/bar'
164
-valid_ref_normalized 'foo.lock///bar' 'foo.lock/bar'
163
+invalid_ref_normalized 'foo.lock/bar'
164
+invalid_ref_normalized 'foo.lock///bar'
165
166
test_done