From: Stephen Haberman Date: Fri, 3 Oct 2008 07:00:03 +0000 (-0500) Subject: Upgrade the client post-checkout hook to automatically reset the merge attribute... X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=49596fba8fe37596628276ca5f5d3ca01f1fa1c1;p=git-central.git Upgrade the client post-checkout hook to automatically reset the merge attribute for stable-cloned branches. --- diff --git a/client/post-checkout-rebase b/client/post-checkout-rebase index 883fa3f..423fb66 100644 --- a/client/post-checkout-rebase +++ b/client/post-checkout-rebase @@ -1,18 +1,26 @@ #!/bin/sh -# The hook is given three parameters: the ref of the previous HEAD, the ref of -# the new HEAD (which may or may not have changed), and a flag indicating -# whether the checkout was a branch checkout (changing branches, flag=1) or a -# file checkout (retrieving a file from the index, flag=0). +# $1 = previous hash +# $2 = new hash (could be the same) +# $3 = flag (0=retreiving from index, 1=new checkout) -branch=$(git symbolic-ref HEAD 2>/dev/null) +branch=$(git symbolic-ref --quiet HEAD) if [[ $? -ne 0 ]] ; then exit 0 fi branch=${branch/refs\/heads\//} -git config --list | grep "branch.${branch}.rebase" > /dev/null +rebase=$(git config "branch.${branch}.rebase") if [ $? -ne 0 ] ; then - git config --add "branch.${branch}.rebase" true + git config "branch.${branch}.rebase" "true" fi + +merge=$(git config "branch.${branch}.merge") +remote=$(git config "branch.${branch}.remote") +if [ "$branch" != "stable" -a "$remote" == "origin" -a "$merge" == "refs/heads/stable" ] ; then + git config "branch.${branch}.merge" "refs/heads/${branch}" +fi + +exit 0 + diff --git a/tests/t1100-client-post-commit-rebase.sh b/tests/t1100-client-post-commit-rebase.sh index af83b20..f47364c 100644 --- a/tests/t1100-client-post-commit-rebase.sh +++ b/tests/t1100-client-post-commit-rebase.sh @@ -7,11 +7,15 @@ test_description='client checkout auto-set branch rebase=true' test_expect_success 'setup' ' echo "setup" >file && git add file && - git commit -m "setup" + git commit -m "setup" && + git clone . ./server && + git remote add origin ./server && + git config branch.master.remote origin && + git config branch.master.merge refs/heads/master ' # setup the post-checkout hook -install_client_hook 'post-checkout-rebase' 'post-checkout' +install_post_checkout_hook 'post-checkout-rebase' test_expect_success 'sets rebase on new topic branch' ' ! git config --list | grep branch.master.rebase && @@ -19,5 +23,19 @@ test_expect_success 'sets rebase on new topic branch' ' git config --list | grep branch.topic.rebase=true ' +test_expect_success 'checking out remote branch does nothing' ' + git push origin topic:topic2 && + git fetch && + git checkout origin/topic2 && + ! git config --list | grep "branch..rebase" +' + +test_expect_success 'cloning stable sets up the correct merge' ' + git push origin topic:stable && + git fetch && + git checkout -b topic3 origin/stable && + test "refs/heads/topic3" = "$(git config branch.topic3.merge)" +' + test_done diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 16099b7..01d0cee 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -453,10 +453,24 @@ install_client_hook () { chmod +x "$TRASH_HOOKS/$2" } +install_post_checkout_hook () { + mkdir -p ".git/hooks" + hook=".git/hooks/post-checkout" + + echo "#!/bin/sh" >$hook + for ((i=1;i<=$#;i+=1)); do + eval script_name="$"$i + echo "../../client/$script_name \$1 \$2 \$3 &&" >>$hook + done + echo "echo >/dev/null" >>$hook + + chmod +x $hook +} + install_server_hook () { - mkdir -p "server/.git/hooks" - cp "../../server/$1" "server/.git/hooks/$2" - chmod +x "server/.git/hooks/$2" + mkdir -p "server/.git/hooks" + cp "../../server/$1" "server/.git/hooks/$2" + chmod +x "server/.git/hooks/$2" } install_update_hook () {