Skip to content

Commit

Permalink
Don't permit ref/branch names to end with ".lock"
Browse files Browse the repository at this point in the history
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 <spearce@spearce.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Mar 25, 2009
1 parent cbdffe4 commit 3e262b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Documentation/git-check-ref-format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ imposes the following rules on how refs are named:

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

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

. They cannot contain a sequence `@{`.

These rules makes it easy for shell script based tools to parse
Expand Down
3 changes: 3 additions & 0 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
* - it has double dots "..", or
* - it has ASCII control character, "~", "^", ":" or SP, anywhere, or
* - it ends with a "/".
* - it ends with ".lock"
*/

static inline int bad_ref_char(int ch)
Expand Down Expand Up @@ -737,6 +738,8 @@ int check_ref_format(const char *ref)
return CHECK_REF_FORMAT_ERROR;
if (level < 2)
return CHECK_REF_FORMAT_ONELEVEL;
if (has_extension(ref, ".lock"))
return CHECK_REF_FORMAT_ERROR;
return ret;
}
}
Expand Down

0 comments on commit 3e262b9

Please sign in to comment.