Skip to content

Commit 3e262b9

Browse files
spearcegitster
authored andcommitted
Don't permit ref/branch names to end with ".lock"
We already skip over loose refs under $GIT_DIR/refs if the name ends with ".lock", so creating a branch named "foo.lock" will not appear in the output of "git branch", "git for-each-ref", nor will its commit be considered reachable by "git rev-list --all". In the latter case this is especially evil, as it may cause repository corruption when objects reachable only through such a ref are deleted by "git prune". It should be reasonably safe to deny use of ".lock" as a ref suffix. In prior versions of Git such branches would be "phantom branches"; you can create it, but you can't see it in "git branch" output. Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbdffe4 commit 3e262b9

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Documentation/git-check-ref-format.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ imposes the following rules on how refs are named:
3434

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

37+
. They cannot end with the sequence `.lock`.
38+
3739
. They cannot contain a sequence `@{`.
3840

3941
These rules makes it easy for shell script based tools to parse

refs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
676676
* - it has double dots "..", or
677677
* - it has ASCII control character, "~", "^", ":" or SP, anywhere, or
678678
* - it ends with a "/".
679+
* - it ends with ".lock"
679680
*/
680681

681682
static inline int bad_ref_char(int ch)
@@ -737,6 +738,8 @@ int check_ref_format(const char *ref)
737738
return CHECK_REF_FORMAT_ERROR;
738739
if (level < 2)
739740
return CHECK_REF_FORMAT_ONELEVEL;
741+
if (has_extension(ref, ".lock"))
742+
return CHECK_REF_FORMAT_ERROR;
740743
return ret;
741744
}
742745
}

0 commit comments

Comments
 (0)