From 2cc12dd1e867b34569924d6008972b98ffe353f9 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Wed, 24 Sep 2008 14:13:01 -0500 Subject: [PATCH] Reproduce and fix with gc-pull the merge replay problem. --- client/post-checkout-rebase | 6 ++-- scripts/gc-pull | 19 +++++++--- scripts/gc-push | 8 ++++- tests/t5200-script-pull.sh | 69 +++++++++++++++++-------------------- 4 files changed, 56 insertions(+), 46 deletions(-) diff --git a/client/post-checkout-rebase b/client/post-checkout-rebase index 40ee523..a0fc533 100644 --- a/client/post-checkout-rebase +++ b/client/post-checkout-rebase @@ -5,14 +5,14 @@ # whether the checkout was a branch checkout (changing branches, flag=1) or a # file checkout (retrieving a file from the index, flag=0). -branch=$(git symbolic-ref --quiet HEAD) -if [ $? -ne 0 ] ; then +branch=$(git symbolic-ref HEAD 2>/dev/null) +if [[ $? -ne 0 ]] ; then exit 0 fi branch=${branch/refs\/heads\//} + git config --list | grep "branch.${branch}.rebase" > /dev/null if [ $? -ne 0 ] ; then git config --add "branch.${branch}.rebase" true fi - diff --git a/scripts/gc-pull b/scripts/gc-pull index 1844725..fcde7b9 100644 --- a/scripts/gc-pull +++ b/scripts/gc-pull @@ -1,7 +1,18 @@ #!/bin/sh +#!/bin/sh + +branch_name=$(git symbolic-ref --quiet HEAD) +if [[ $? -ne 0 ]] ; then + echo "not on a branch" + exit 1 +fi + +branch_name=${branch_name/refs\/heads\//} + +git fetch +if [[ $? -ne 0 ]] ; then + exit $? +fi -# -# Note: we should use `git pull --rebase origin `? -# -git pull --rebase $* +GIT_EDITOR=: git rebase -p -i "origin/$branch_name" diff --git a/scripts/gc-push b/scripts/gc-push index 32952b1..4e72fe5 100644 --- a/scripts/gc-push +++ b/scripts/gc-push @@ -1,6 +1,12 @@ #!/bin/sh -branch_name=$(git-symbolic-ref HEAD) +branch_name=$(git symbolic-ref --quiet HEAD) +if [[ $? -ne 0 ]] ; then + echo "not on a branch" + exit 1 +fi + +branch_name=${branch_name/refs\/heads\//} git push origin $branch_name if [[ $? -ne 0 ]] ; then diff --git a/tests/t5200-script-pull.sh b/tests/t5200-script-pull.sh index 3bfd5e4..39e660d 100644 --- a/tests/t5200-script-pull.sh +++ b/tests/t5200-script-pull.sh @@ -32,46 +32,39 @@ test_expect_success 'pull does a rebase' ' # Only one parent gc-pull && - git cat-file commit $(git rev-parse HEAD) | grep parent | wc -l | grep 1 + test 1 = $(git cat-file commit $(git rev-parse HEAD) | grep parent | wc -l) ' -#test_expect_success 'pull does a rebase but does not fuck up merges' ' -# # Change "a" itself so we will eventually conflict -# gc-checkout topic2 && -# echo "$test_name on topic2" >a && -# git commit -a -m "move topic2" && -# -# # Change a.topic2 as well for another commit to continue rebasing after fixing the conflict -# echo "$test_name on topic2" >a.topic2 && -# git add a.topic2 && -# git commit -m "move a.topic2" && -# -# # Move stable -# git checkout stable && -# echo "$test_name on stable" >a && -# git commit -a -m "move stable" && -# git push origin stable && -# -# # Move topic2 on the server, then merge stable -# cd server && -# git checkout stable && -# echo "$test_name on stable server" >a.stable.server && -# git add a.stable.server && -# git commit -m "move stable server" && -# git checkout topic2 && -# echo "$test_name" >a.topic2.server && -# git add a.topic2.server && -# git commit -m "move topic2 on the server" && -# git merge stable && -# cd .. && -# -# # Merge stable locally too--should conflict -# git checkout topic2 && -# git merge origin/stable -# -# # Now pull and see what happens -# # gc-pull -#' +test_expect_success 'pull does a rebase but does not fuck up merges' ' + gc-checkout topic2 && + echo "$test_name on topic2" >a.topic2 && + git add a.topic2 && + git commit -a -m "create topic2" && + git push origin topic2 && + + # Move stable + git checkout stable && + echo "$test_name on stable" >a && + git commit -a -m "move stable that will not be replayed" && + git push origin stable && + + # And merge stable into topic2 + git checkout topic2 && + git merge stable && + + # Move topic2 on the server + cd server && + git checkout topic2 && + echo "$test_name" >a.topic2.server && + git add a.topic2.server && + git commit -m "move topic2 on the server" && + cd .. && + + # Merge stable locally too--should conflict + git checkout topic2 && + gc-pull && + test 1 = $(git rev-list --all --pretty=oneline | grep "replayed" | wc -l) +' test_done -- 2.39.5