Code

clone: Supply the right commit hash to post-checkout when -b is used
authorBjörn Steinbrink <B.Steinbrink@gmx.de>
Tue, 13 Oct 2009 22:11:09 +0000 (00:11 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Oct 2009 08:19:15 +0000 (01:19 -0700)
When we use -b <branch>, we may checkout something else than what the
remote's HEAD references, but we still used remote_head to supply the
new ref value to the post-checkout hook, which is wrong.

So instead of using remote_head to find the value to be passed to the
post-checkout hook, we have to use our_head_points_at, which is always
correctly setup, even if -b is not used.

This also fixes a segfault when "clone -b <branch>" is used with a
remote repo that doesn't have a valid HEAD, as in such a case
remote_head is NULL, but we still tried to access it.

Reported-by: Devin Cofer <ranguvar@archlinux.us>
Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-clone.c
remote-curl.c

index 4992c2597c903d86ce1d0c209828aeb962fef23a..5762a6f9d8191c79d4fd66d227038d59ab1e785e 100644 (file)
@@ -641,7 +641,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                        die("unable to write new index file");
 
                err |= run_hook(NULL, "post-checkout", sha1_to_hex(null_sha1),
-                               sha1_to_hex(remote_head->old_sha1), "1", NULL);
+                               sha1_to_hex(our_head_points_at->old_sha1), "1",
+                               NULL);
 
                if (!err && option_recursive)
                        err = run_command_v_opt(argv_submodule, RUN_GIT_CMD);
index d8d276a471b0c5a819ca1b2e02e9b3a6cd27cd73..2faf1c634415d139f15c4829937e0460be31dc1d 100644 (file)
@@ -3,6 +3,7 @@
 #include "strbuf.h"
 #include "walker.h"
 #include "http.h"
+#include "exec_cmd.h"
 
 static struct ref *get_refs(struct walker *walker, const char *url)
 {