#!/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
+
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 &&
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
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 () {