Skip to content

Commit

Permalink
Do not allow ".lock" at the end of any refname component
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Oct 5, 2011
1 parent 49295d4 commit 7e9d2fe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions Documentation/git-check-ref-format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ git imposes the following rules on how references are named:

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

. They must contain at least one `/`. This enforces the presence of a
category like `heads/`, `tags/` etc. but the actual names are not
Expand All @@ -47,8 +47,6 @@ git imposes the following rules on how references are named:

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

. They cannot end with the sequence `.lock`.

. They cannot contain a sequence `@{`.

. They cannot contain a `\`.
Expand Down
4 changes: 2 additions & 2 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,8 @@ static int check_refname_component(const char *ref)
return -1; /* Component has zero length. */
if (ref[0] == '.')
return -1; /* Component starts with '.'. */
if (cp - ref >= 5 && !memcmp(cp - 5, ".lock", 5))
return -1; /* Refname ends with ".lock". */
return cp - ref;
}

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

if (ref[component_len - 1] == '.')
return -1; /* Refname ends with '.'. */
if (component_len >= 5 && !memcmp(&ref[component_len - 5], ".lock", 5))
return -1; /* Refname ends with ".lock". */
if (!(flags & REFNAME_ALLOW_ONELEVEL) && component_count < 2)
return -1; /* Refname has only one component. */
return 0;
Expand Down
8 changes: 4 additions & 4 deletions t/t1402-check-ref-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ invalid_ref 'heads/foo?bar'
valid_ref 'foo./bar'
invalid_ref 'heads/foo.lock'
invalid_ref 'heads///foo.lock'
valid_ref 'foo.lock/bar'
valid_ref 'foo.lock///bar'
invalid_ref 'foo.lock/bar'
invalid_ref 'foo.lock///bar'
valid_ref 'heads/foo@bar'
invalid_ref 'heads/v@{ation'
invalid_ref 'heads/foo\bar'
Expand Down Expand Up @@ -160,7 +160,7 @@ invalid_ref_normalized 'heads/./foo'
invalid_ref_normalized 'heads\foo'
invalid_ref_normalized 'heads/foo.lock'
invalid_ref_normalized 'heads///foo.lock'
valid_ref_normalized 'foo.lock/bar' 'foo.lock/bar'
valid_ref_normalized 'foo.lock///bar' 'foo.lock/bar'
invalid_ref_normalized 'foo.lock/bar'
invalid_ref_normalized 'foo.lock///bar'

test_done

0 comments on commit 7e9d2fe

Please sign in to comment.