Skip to content

Commit 7e9d2fe

Browse files
mhaggergitster
authored andcommitted
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>
1 parent 49295d4 commit 7e9d2fe

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

Documentation/git-check-ref-format.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ git imposes the following rules on how references are named:
2828

2929
. They can include slash `/` for hierarchical (directory)
3030
grouping, but no slash-separated component can begin with a
31-
dot `.`.
31+
dot `.` or end with the sequence `.lock`.
3232

3333
. They must contain at least one `/`. This enforces the presence of a
3434
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:
4747

4848
. They cannot end with a slash `/` nor a dot `.`.
4949

50-
. They cannot end with the sequence `.lock`.
51-
5250
. They cannot contain a sequence `@{`.
5351

5452
. They cannot contain a `\`.

refs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,8 @@ static int check_refname_component(const char *ref)
898898
return -1; /* Component has zero length. */
899899
if (ref[0] == '.')
900900
return -1; /* Component starts with '.'. */
901+
if (cp - ref >= 5 && !memcmp(cp - 5, ".lock", 5))
902+
return -1; /* Refname ends with ".lock". */
901903
return cp - ref;
902904
}
903905

@@ -931,8 +933,6 @@ int check_refname_format(const char *ref, int flags)
931933

932934
if (ref[component_len - 1] == '.')
933935
return -1; /* Refname ends with '.'. */
934-
if (component_len >= 5 && !memcmp(&ref[component_len - 5], ".lock", 5))
935-
return -1; /* Refname ends with ".lock". */
936936
if (!(flags & REFNAME_ALLOW_ONELEVEL) && component_count < 2)
937937
return -1; /* Refname has only one component. */
938938
return 0;

t/t1402-check-ref-format.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ invalid_ref 'heads/foo?bar'
4343
valid_ref 'foo./bar'
4444
invalid_ref 'heads/foo.lock'
4545
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'
4848
valid_ref 'heads/foo@bar'
4949
invalid_ref 'heads/v@{ation'
5050
invalid_ref 'heads/foo\bar'
@@ -160,7 +160,7 @@ invalid_ref_normalized 'heads/./foo'
160160
invalid_ref_normalized 'heads\foo'
161161
invalid_ref_normalized 'heads/foo.lock'
162162
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'
165165

166166
test_done

0 commit comments

Comments
 (0)