path: root/builtin/checkout.c
diff options
authorErik Faye-Lund <>2012-05-08 17:22:33 (GMT)
committerJunio C Hamano <>2012-05-08 17:36:55 (GMT)
commit8338f771fe9720766dfcb25b6dca58832e24a0fd (patch)
tree6bb1594c45fffde796364ee577ff34cf548fee17 /builtin/checkout.c
parentabe199808c6586047fb7255b80e3d17ffc26bf6c (diff)
checkout: do not corrupt HEAD on empty repo
In abe1998 ("git checkout -b: allow switching out of an unborn branch"), a code-path overly-optimisticly assumed that a branch-name was specified. This is not always the case, and as a result a NULL-pointer was attempted printed to .git/HEAD. This could lead to at least two different failure modes: 1) vsnprintf formated the NULL-string as something useful (e.g "(null)") 2) vsnprintf crashed Neither were very convenient for formatting a new HEAD-reference. To fix this, reintroduce some strictness so we only take this new codepath if a banch-name was specified. Signed-off-by: Erik Faye-Lund <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/checkout.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index b76e2c0..44ecc22 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1100,7 +1100,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
if (opts.writeout_stage)
die(_("--ours/--theirs is incompatible with switching branches."));
- if (!new.commit) {
+ if (!new.commit && opts.new_branch) {
unsigned char rev[20];
int flag;