#!/bin/sh global test_description := ''test custom script in place of pack-objects'' source ./test-lib.sh test_expect_success 'create some history to fetch' ' test_commit one && test_commit two ' test_expect_success 'create debugging hook script' ' write_script .git/hook <<-\EOF echo >&2 "hook running" echo "$*" >hook.args cat >hook.stdin "$@" hook.stdout cat hook.stdout EOF ' proc clear_hook_results { rm -rf .git/hook.* dst.git } test_expect_success 'hook runs via global config' ' clear_hook_results && test_config_global uploadpack.packObjectsHook ./hook && git clone --no-local . dst.git 2>stderr && grep "hook running" stderr ' test_expect_success 'hook outputs are sane' ' # check that we recorded a usable pack git index-pack --stdin <.git/hook.stdout && # check that we recorded args and stdin. We do not check # the full argument list or the exact pack contents, as it would make # the test brittle. So just sanity check that we could replay # the packing procedure. grep "^git" .git/hook.args && $(cat .git/hook.args) <.git/hook.stdin >replay ' test_expect_success 'hook runs from -c config' ' clear_hook_results && git clone --no-local \ -u "git -c uploadpack.packObjectsHook=./hook upload-pack" \ . dst.git 2>stderr && grep "hook running" stderr ' test_expect_success 'hook does not run from repo config' ' clear_hook_results && test_config uploadpack.packObjectsHook "./hook" && git clone --no-local . dst.git 2>stderr && ! grep "hook running" stderr && test_path_is_missing .git/hook.args && test_path_is_missing .git/hook.stdin && test_path_is_missing .git/hook.stdout ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"test custom script in place of pack-objects">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"create some history to fetch">)} {(SQ <"\n"> <"\ttest_commit one &&\n"> <"\ttest_commit two\n">)} ) (C {(test_expect_success)} {(SQ <"create debugging hook script">)} { (SQ <"\n"> <"\twrite_script .git/hook <<-\\EOF\n"> <"\t\techo >&2 \"hook running\"\n"> <"\t\techo \"$*\" >hook.args\n"> <"\t\tcat >hook.stdin\n"> <"\t\t\"$@\" hook.stdout\n"> <"\t\tcat hook.stdout\n"> <"\tEOF\n"> ) } ) (FuncDef name: clear_hook_results body: (BraceGroup children: [(C {(rm)} {(-rf)} {(.git/hook.) (Lit_Other "*")} {(dst.git)})] spids: [50] ) spids: [45 49] ) (C {(test_expect_success)} {(SQ <"hook runs via global config">)} { (SQ <"\n"> <"\tclear_hook_results &&\n"> <"\ttest_config_global uploadpack.packObjectsHook ./hook &&\n"> <"\tgit clone --no-local . dst.git 2>stderr &&\n"> <"\tgrep \"hook running\" stderr\n"> ) } ) (C {(test_expect_success)} {(SQ <"hook outputs are sane">)} { (SQ <"\n"> <"\t# check that we recorded a usable pack\n"> <"\tgit index-pack --stdin <.git/hook.stdout &&\n"> <"\n"> <"\t# check that we recorded args and stdin. We do not check\n"> <"\t# the full argument list or the exact pack contents, as it would make\n"> <"\t# the test brittle. So just sanity check that we could replay\n"> <"\t# the packing procedure.\n"> <"\tgrep \"^git\" .git/hook.args &&\n"> <"\t$(cat .git/hook.args) <.git/hook.stdin >replay\n"> ) } ) (C {(test_expect_success)} {(SQ <"hook runs from -c config">)} { (SQ <"\n"> <"\tclear_hook_results &&\n"> <"\tgit clone --no-local \\\n"> <"\t -u \"git -c uploadpack.packObjectsHook=./hook upload-pack\" \\\n"> <"\t . dst.git 2>stderr &&\n"> <"\tgrep \"hook running\" stderr\n"> ) } ) (C {(test_expect_success)} {(SQ <"hook does not run from repo config">)} { (SQ <"\n"> <"\tclear_hook_results &&\n"> <"\ttest_config uploadpack.packObjectsHook \"./hook\" &&\n"> <"\tgit clone --no-local . dst.git 2>stderr &&\n"> <"\t! grep \"hook running\" stderr &&\n"> <"\ttest_path_is_missing .git/hook.args &&\n"> <"\ttest_path_is_missing .git/hook.stdin &&\n"> <"\ttest_path_is_missing .git/hook.stdout\n"> ) } ) (C {(test_done)}) ] )