{"thread":{"id":"24724","subject":"[PATCHv5 0/2] Fix spurious conflicts with pull --rebase","startedAt":"2010-08-13T01:48:52Z","lastAt":"2010-08-13T01:50:50Z","messageCount":4,"participants":["Elijah Newren","Ævar Arnfjörð Bjarmason"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"147985","messageId":"AANLkTi=9Mqyoc5jjMOZJVNGY0e=DqZUr7ays=WOcr2tN@mail.gmail.com","threadId":"24724","inReplyTo":"1281664250-2703-1-git-send-email-newren@gmail.com","subject":"Re: [PATCHv5 0/2] Fix spurious conflicts with pull --rebase","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-08-13T01:48:52Z","receivedAt":"2010-08-13T01:48:52Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This looks very good, and has a great code/test ratio.\n"},{"id":"147981","messageId":"1281664250-2703-1-git-send-email-newren@gmail.com","threadId":"24724","inReplyTo":null,"subject":"[PATCHv5 0/2] Fix spurious conflicts with pull --rebase","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2010-08-13T01:50:48Z","receivedAt":"2010-08-13T01:50:48Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"Changes since v4\n  * Added a little bit of detail to the commit log about cases when\n    the change can affect\n  * Fixed issue pointed out by Santi with moving 12 lines of code (to\n    bring definition of oldupstream variable together); the different\n    pieces had important reasons for being where they were.\nChanges since v1\n  * Changes above, plus other commit log wording changes and lots of\n    style and formatting issues for the testcase\n\nThis patch series fixes spurious conflict issues with git pull\n--rebase for the case where the upstream repository is *not* rebased.\n(There is no change in the case where the upstream repository is\nrebased.)\n\nIn cc85c792 (pull --rebase: be cleverer with rebased upstream\nbranches, 2008-01-26) and d44e712 (pull: support rebased upstream +\nfetch + pull --rebase, 2009-07-19), the call to git-rebase was\nmodified in an effort to reduce the number of commits being reapplied,\nby trying to avoid commits that upstream already had or has.  It was\nspecifically designed with an upstream that is rebased in mind.\nUnfortunately, it had two side effects for the non-rebased upstream\ncase: (1) it prevented detecting if \"local\" patches are already\nupstream, and (2) it could in some cases cause more patches known to\nbe upstream to be reapplied rather than less.  This series fixes both\nof these issues for the non-rebased upstream case.  See the commit\nmessage of the second patch for details.\n\nIt's worth noting that issue (1) above also affects the case where the\nupstream repository has been rebased, which this patch series does not\naddress.  As far as I can tell, fixing it would require changes\n(including new syntax) to format-patch to allow it to be told what\n'upstream' is, and some changes to git-pull.sh/git-rebase.sh to pass\nit this information.\n\nElijah Newren (2):\n  t5520-pull: Add testcases showing spurious conflicts from git pull\n    --rebase\n  pull --rebase: Avoid spurious conflicts and reapplying unnecessary\n    patches\n\n git-pull.sh     |    9 ++++++++\n t/t5520-pull.sh |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 71 insertions(+), 0 deletions(-)\n\n-- \n1.7.2.1.43.gbae63\n"},{"id":"147982","messageId":"1281664250-2703-2-git-send-email-newren@gmail.com","threadId":"24724","inReplyTo":"1281664250-2703-1-git-send-email-newren@gmail.com","subject":"[PATCHv5 1/2] t5520-pull: Add testcases showing spurious conflicts from git pull --rebase","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2010-08-13T01:50:49Z","receivedAt":"2010-08-13T01:50:49Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"\nSigned-off-by: Elijah Newren <newren@gmail.com>\n---\n t/t5520-pull.sh |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 62 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t5520-pull.sh b/t/t5520-pull.sh\nindex 319e389..85a6b23 100755\n--- a/t/t5520-pull.sh\n+++ b/t/t5520-pull.sh\n@@ -4,6 +4,11 @@ test_description='pulling into void'\n \n . ./test-lib.sh\n \n+modify () {\n+\tsed -e \"$1\" <\"$2\" >\"$2.x\" &&\n+\tmv \"$2.x\" \"$2\"\n+}\n+\n D=`pwd`\n \n test_expect_success setup '\n@@ -160,4 +165,61 @@ test_expect_success 'pull --rebase works on branch yet to be born' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'setup for detecting upstreamed changes' '\n+\tmkdir src &&\n+\t(cd src &&\n+\t git init &&\n+\t printf \"1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n\" > stuff &&\n+\t git add stuff &&\n+\t git commit -m \"Initial revision\"\n+\t) &&\n+\tgit clone src dst &&\n+\t(cd src &&\n+\t modify s/5/43/ stuff &&\n+\t git commit -a -m \"5->43\" &&\n+\t modify s/6/42/ stuff &&\n+\t git commit -a -m \"Make it bigger\"\n+\t) &&\n+\t(cd dst &&\n+\t modify s/5/43/ stuff &&\n+\t git commit -a -m \"Independent discovery of 5->43\"\n+\t)\n+'\n+\n+test_expect_failure 'git pull --rebase detects upstreamed changes' '\n+\t(cd dst &&\n+\t git pull --rebase &&\n+\t test -z \"$(git ls-files -u)\"\n+\t)\n+'\n+\n+test_expect_success 'setup for avoiding reapplying old patches' '\n+\t(cd dst &&\n+\t test_might_fail git rebase --abort &&\n+\t git reset --hard origin/master\n+\t) &&\n+\tgit clone --bare src src-replace.git &&\n+\trm -rf src &&\n+\tmv src-replace.git src &&\n+\t(cd dst &&\n+\t modify s/2/22/ stuff &&\n+\t git commit -a -m \"Change 2\" &&\n+\t modify s/3/33/ stuff &&\n+\t git commit -a -m \"Change 3\" &&\n+\t modify s/4/44/ stuff &&\n+\t git commit -a -m \"Change 4\" &&\n+\t git push &&\n+\n+\t modify s/44/55/ stuff &&\n+\t git commit --amend -a -m \"Modified Change 4\"\n+\t)\n+'\n+\n+test_expect_failure 'git pull --rebase does not reapply old patches' '\n+\t(cd dst &&\n+\t test_must_fail git pull --rebase &&\n+\t test 1 = $(find .git/rebase-apply -name \"000*\" | wc -l)\n+\t)\n+'\n+\n test_done\n-- \n1.7.2.1.43.gbae63\n"},{"id":"147983","messageId":"1281664250-2703-3-git-send-email-newren@gmail.com","threadId":"24724","inReplyTo":"1281664250-2703-1-git-send-email-newren@gmail.com","subject":"[PATCHv5 2/2] pull --rebase: Avoid spurious conflicts and reapplying unnecessary patches","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2010-08-13T01:50:50Z","receivedAt":"2010-08-13T01:50:50Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"Prior to c85c792 (pull --rebase: be cleverer with rebased upstream\nbranches, 2008-01-26), pull --rebase would run\n  git rebase $merge_head\nwhich resulted in a call to\n  git format-patch ... --ignore-if-in-upstream $merge_head..$cur_branch\n\nThis resulted in patches from $merge_head..$cur_branch being applied, as\nlong as they did not already exist in $cur_branch..$merge_head.\nUnfortunately, when upstream is rebased, $merge_head..$cur_branch also\nrefers to \"old\" commits that have already been rebased upstream, meaning\nthat many patches that were already fixed upstream would be reapplied.\nThis could result in many spurious conflicts, as well as reintroduce\npatches that were intentionally dropped upstream.\n\nSo the algorithm was changed in c85c792 (pull --rebase: be cleverer with\nrebased upstream branches, 2008-01-26) and d44e712 (pull: support rebased\nupstream + fetch + pull --rebase, 2009-07-19).  Defining $old_remote_ref to\nbe the most recent entry in the reflog for @{upstream} that is an ancestor\nof $cur_branch, pull --rebase was changed to run\n  git rebase --onto $merge_head $old_remote_ref\nwhich results in a call to\n  git format-patch ... --ignore-if-in-upstream $old_remote_ref..$cur_branch\n\nThe whole point of this change was to reduce the number of commits being\nreapplied, by avoiding commits that upstream already has or had.\n\nIn the rebased upstream case, this change achieved that purpose.  It is\nworth noting, though, that since $old_remote_ref is always an ancestor of\n$cur_branch (by its definition), format-patch will not know what upstream\nis and thus will not be able to determine if any patches are already\nupstream; they will all be reapplied.\n\nIn the non-rebased upstream case, this new form is usually the same as the\noriginal code but in some cases $old_remote_ref can be an ancestor of\n   $(git merge-base $merge_head $cur_branch)\nmeaning that instead of avoiding reapplying commits that upstream already\nhas, it actually includes more such commits.  Combined with the fact that\nformat-patch can no longer detect commits that are already upstream (since\nit is no longer told what upstream is), results in lots of confusion for\nusers (e.g. \"git is giving me lots of conflicts in stuff I didn't even\nchange since my last push.\")\n\nCases where additional commits could be reapplied include forking from a\ncommit other than the tracking branch, or amending/rebasing after pushing.\nCases where the inability to detect upstreamed commits cause problems\ninclude independent discovery of a fix and having your patches get\nupstreamed by some alternative route (e.g. pulling your changes to a third\nmachine, pushing from there, and then going back to your original machine\nand trying to pull --rebase).\n\nFix the non-rebased upstream case by ignoring $old_remote_ref whenever it\nis contained in $(git merge-base $merge_head $cur_branch).  This should\nhave no affect on the rebased upstream case.\n\nAcked-by: Santi Béjar <santi@agolina.net>\nSigned-off-by: Elijah Newren <newren@gmail.com>\n---\n git-pull.sh     |    9 +++++++++\n t/t5520-pull.sh |    4 ++--\n 2 files changed, 11 insertions(+), 2 deletions(-)\n\ndiff --git a/git-pull.sh b/git-pull.sh\nindex a09a44e..8eb74d4 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -273,6 +273,15 @@ then\n \texit\n fi\n \n+if test true = \"$rebase\"\n+then\n+\to=$(git show-branch --merge-base $curr_branch $merge_head $oldremoteref)\n+\tif test \"$oldremoteref\" = \"$o\"\n+\tthen\n+\t\tunset oldremoteref\n+\tfi\n+fi\n+\n merge_name=$(git fmt-merge-msg $log_arg <\"$GIT_DIR/FETCH_HEAD\") || exit\n case \"$rebase\" in\n true)\ndiff --git a/t/t5520-pull.sh b/t/t5520-pull.sh\nindex 85a6b23..0b489f5 100755\n--- a/t/t5520-pull.sh\n+++ b/t/t5520-pull.sh\n@@ -186,7 +186,7 @@ test_expect_success 'setup for detecting upstreamed changes' '\n \t)\n '\n \n-test_expect_failure 'git pull --rebase detects upstreamed changes' '\n+test_expect_success 'git pull --rebase detects upstreamed changes' '\n \t(cd dst &&\n \t git pull --rebase &&\n \t test -z \"$(git ls-files -u)\"\n@@ -215,7 +215,7 @@ test_expect_success 'setup for avoiding reapplying old patches' '\n \t)\n '\n \n-test_expect_failure 'git pull --rebase does not reapply old patches' '\n+test_expect_success 'git pull --rebase does not reapply old patches' '\n \t(cd dst &&\n \t test_must_fail git pull --rebase &&\n \t test 1 = $(find .git/rebase-apply -name \"000*\" | wc -l)\n-- \n1.7.2.1.43.gbae63\n"}]}