Skip to content

Commit d01a8e3

Browse files
dotdashgitster
authored andcommitted
clone: Supply the right commit hash to post-checkout when -b is used
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 <[email protected]> Signed-off-by: Björn Steinbrink <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c6dfb39 commit d01a8e3

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

builtin-clone.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
641641
die("unable to write new index file");
642642

643643
err |= run_hook(NULL, "post-checkout", sha1_to_hex(null_sha1),
644-
sha1_to_hex(remote_head->old_sha1), "1", NULL);
644+
sha1_to_hex(our_head_points_at->old_sha1), "1",
645+
NULL);
645646

646647
if (!err && option_recursive)
647648
err = run_command_v_opt(argv_submodule, RUN_GIT_CMD);

remote-curl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "strbuf.h"
44
#include "walker.h"
55
#include "http.h"
6+
#include "exec_cmd.h"
67

78
static struct ref *get_refs(struct walker *walker, const char *url)
89
{

0 commit comments

Comments
 (0)