Skip to content

Commit 8a396c0

Browse files
committed
Merge branch 'jk/clone-post-checkout'
* jk/clone-post-checkout: clone: run post-checkout hook when checking out
2 parents 5a5bd23 + dfa7a6c commit 8a396c0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

builtin-clone.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "dir.h"
2121
#include "pack-refs.h"
2222
#include "sigchain.h"
23+
#include "run-command.h"
2324

2425
/*
2526
* Overall FIXMEs:
@@ -375,6 +376,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
375376
struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
376377
struct transport *transport = NULL;
377378
char *src_ref_prefix = "refs/heads/";
379+
int err = 0;
378380

379381
struct refspec refspec;
380382

@@ -625,12 +627,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
625627
if (write_cache(fd, active_cache, active_nr) ||
626628
commit_locked_index(lock_file))
627629
die("unable to write new index file");
630+
631+
err |= run_hook(NULL, "post-checkout", sha1_to_hex(null_sha1),
632+
sha1_to_hex(remote_head->old_sha1), "1", NULL);
628633
}
629634

630635
strbuf_release(&reflog_msg);
631636
strbuf_release(&branch_top);
632637
strbuf_release(&key);
633638
strbuf_release(&value);
634639
junk_pid = 0;
635-
return 0;
640+
return err;
636641
}

t/t5403-post-checkout-hook.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,16 @@ test_expect_success 'post-checkout receives the right args when not switching br
7171
test $old = $new -a $flag = 0
7272
'
7373

74+
mkdir -p templates/hooks
75+
cat >templates/hooks/post-checkout <<'EOF'
76+
#!/bin/sh
77+
echo $@ > $GIT_DIR/post-checkout.args
78+
EOF
79+
chmod +x templates/hooks/post-checkout
80+
81+
test_expect_success 'post-checkout hook is triggered by clone' '
82+
git clone --template=templates . clone3 &&
83+
test -f clone3/.git/post-checkout.args
84+
'
85+
7486
test_done

0 commit comments

Comments
 (0)