{"thread":{"id":"26439","subject":"[PATCH] rebase: use @{upstream} if no upstream specified","startedAt":"2011-02-08T00:37:55Z","lastAt":"2011-02-10T02:46:14Z","messageCount":12,"participants":["Martin von Zweigbergk","Sverre Rabbelier","Jonathan Nieder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"160662","messageId":"1297125475-19151-1-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"26439","inReplyTo":null,"subject":"[PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2011-02-08T00:37:55Z","receivedAt":"2011-02-08T00:37:55Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"'git rebase' without arguments is currently not supported. Make it\ndefault to 'git rebase @{upstream}'. That is also what 'git pull\n[--rebase]' defaults to, so it only makes sense that 'git rebase'\ndefaults to the same thing.\n\nDefaulting to @{upstream} will make it possible to run e.g. 'git\nrebase -i' without arguments, which is probably a quite common use\ncase. It also improves the scenario where you have multiple branches\nthat rebase against a remote-tracking branch, where you currently have\nto choose between the extra network delay of 'git pull' or the\nslightly awkward keys to enter 'git rebase @{u}'.\n\nHelped-by: Yann Dirson <ydirson@altern.org>\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\nApplies on top of the rebase refactoring series I sent yesterday, see\nhttp://thread.gmane.org/gmane.comp.version-control.git/166161/\n\n Documentation/config.txt     |    2 +-\n Documentation/git-rebase.txt |   11 +++++++++--\n git-rebase.sh                |   35 +++++++++++++++++++++++++++++------\n t/t3400-rebase.sh            |   25 +++++++++++++++++--------\n 4 files changed, 56 insertions(+), 17 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex c5e1835..b4e65b8 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -646,7 +646,7 @@ branch.<name>.remote::\n \n branch.<name>.merge::\n \tDefines, together with branch.<name>.remote, the upstream branch\n-\tfor the given branch. It tells 'git fetch'/'git pull' which\n+\tfor the given branch. It tells 'git fetch'/'git pull'/'git rebase' which\n \tbranch to merge and can also affect 'git push' (see push.default).\n \tWhen in branch <name>, it tells 'git fetch' the default\n \trefspec to be marked for merging in FETCH_HEAD. The value is\ndiff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt\nindex 96680c8..d3e998d 100644\n--- a/Documentation/git-rebase.txt\n+++ b/Documentation/git-rebase.txt\n@@ -9,7 +9,7 @@ SYNOPSIS\n --------\n [verse]\n 'git rebase' [-i | --interactive] [options] [--onto <newbase>]\n-\t<upstream> [<branch>]\n+\t[<upstream>] [<branch>]\n 'git rebase' [-i | --interactive] [options] --onto <newbase>\n \t--root [<branch>]\n \n@@ -21,6 +21,12 @@ If <branch> is specified, 'git rebase' will perform an automatic\n `git checkout <branch>` before doing anything else.  Otherwise\n it remains on the current branch.\n \n+If <upstream> is not specified, the upstream configured in\n+branch.<name>.remote and branch.<name>.merge options will be used; see\n+linkgit:git-config[1] for details.  If you are currently not on any\n+branch or if the current branch does not have a configured upstream,\n+the rebase will abort.\n+\n All changes made by commits in the current branch but that are not\n in <upstream> are saved to a temporary area.  This is the same set\n of commits that would be shown by `git log <upstream>..HEAD` (or\n@@ -216,7 +222,8 @@ leave out at most one of A and B, in which case it defaults to HEAD.\n \n <upstream>::\n \tUpstream branch to compare against.  May be any valid commit,\n-\tnot just an existing branch name.\n+\tnot just an existing branch name. Defaults to the configured\n+\tupstream for the current branch.\n \n <branch>::\n \tWorking branch; defaults to HEAD.\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex be9ec2a..5975642 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -3,7 +3,7 @@\n # Copyright (c) 2005 Junio C Hamano.\n #\n \n-USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] (<upstream>|--root) [<branch>] [--quiet | -q]'\n+USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]'\n LONG_USAGE='git-rebase replaces <branch> with a new branch of the\n same name.  When the --onto option is provided the new branch starts\n out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>\n@@ -144,6 +144,25 @@ run_pre_rebase_hook () {\n \tfi\n }\n \n+error_on_missing_default_upstream () {\n+\tbranch_name=$(git symbolic-ref -q HEAD)\n+\tif test -z \"$branch_name\"\n+\tthen\n+\t\tdie \"You are not currently on a branch, so I cannot use any\n+'branch.<branchname>.merge' in your configuration file.\n+Please specify which upstream branch you want to use on the command\n+line and try again (e.g. 'git rebase <upstream branch>').\n+See git-rebase(1) for details.\"\n+\telse\n+\t\tdie \"You asked me to rebase without telling me which branch you\n+want to rebase against, and 'branch.${branch_name#refs/heads/}.merge' in\n+your configuration file does not tell me, either. Please\n+specify which branch you want to use on the command line and\n+try again (e.g. 'git rebase <upstream branch>').\n+See git-rebase(1) for details.\"\n+\tfi\n+}\n+\n test -f \"$apply_dir\"/applying &&\n \tdie 'It looks like git-am is in progress. Cannot rebase.'\n \n@@ -345,8 +364,6 @@ and run me again.  I am stopping in case you still have something\n valuable there.'\n fi\n \n-test $# -eq 0 && test -z \"$rebase_root\" && usage\n-\n if test -n \"$interactive_rebase\"\n then\n \ttype=interactive\n@@ -362,9 +379,15 @@ fi\n \n if test -z \"$rebase_root\"\n then\n-\t# The upstream head must be given.  Make sure it is valid.\n-\tupstream_name=\"$1\"\n-\tshift\n+\tcase \"$#\" in\n+\t0)\n+\t\tupstream_name=$(git rev-parse --symbolic-full-name --verify -q \\\n+\t\t@{upstream}) || error_on_missing_default_upstream\n+\t\t;;\n+\t*)\tupstream_name=\"$1\"\n+\t\tshift\n+\t\t;;\n+\tesac\n \tupstream=`git rev-parse --verify \"${upstream_name}^0\"` ||\n \tdie \"invalid upstream $upstream_name\"\n \tupstream_arg=\"$upstream_name\"\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex 349eebd..3bd4a84 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -158,15 +158,24 @@ test_expect_success 'Show verbose error when HEAD could not be detached' '\n '\n rm -f B\n \n-test_expect_success 'dump usage when upstream arg is missing' '\n-\tgit checkout -b usage topic &&\n+test_expect_success 'fail when upstream arg is missing and not on branch' '\n+\tgit checkout topic &&\n \ttest_must_fail git rebase 2>error1 &&\n-\tgrep \"[Uu]sage\" error1 &&\n-\ttest_must_fail git rebase --abort 2>error2 &&\n-\tgrep \"No rebase in progress\" error2 &&\n-\ttest_must_fail git rebase --onto master 2>error3 &&\n-\tgrep \"[Uu]sage\" error3 &&\n-\t! grep \"can.t shift\" error3\n+\tgrep \"You are not currently on a branch\" error1\n+'\n+\n+test_expect_success 'fail when upstream arg is missing and not configured' '\n+\tgit checkout -b no-config topic &&\n+\ttest_must_fail git rebase 2>error2 &&\n+\tgrep \"branch.no-config.merge\" error2\n+'\n+\n+test_expect_success 'default to @{upstream} when upstream arg is missing' '\n+\tgit checkout -b default topic &&\n+\tgit config branch.default.remote .\n+\tgit config branch.default.merge refs/heads/master\n+\tgit rebase &&\n+\ttest \"$(git rev-parse default~1)\" = \"$(git rev-parse master)\"\n '\n \n test_expect_success 'rebase -q is quiet' '\n-- \n1.7.4.rc2.33.g8a14f\n"},{"id":"160705","messageId":"AANLkTi=Uqkzv+ucBzww6R1V+0ujmfH-dED8XJhyRvWQF@mail.gmail.com","threadId":"26439","inReplyTo":"1297125475-19151-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"Re: [PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2011-02-08T17:46:47Z","receivedAt":"2011-02-08T17:46:47Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Tue, Feb 8, 2011 at 01:37, Martin von Zweigbergk\n<martin.von.zweigbergk@gmail.com> wrote:\n> Defaulting to @{upstream} will make it possible to run e.g. 'git\n> rebase -i' without arguments, which is probably a quite common use\n> case.\n\nI particularly like that you explain to the user clearly what they\nhave to do to make this work (e.g., configure the upstream). Nice.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"160707","messageId":"alpine.DEB.2.00.1102081320350.4475@debian","threadId":"26439","inReplyTo":"AANLkTi=Uqkzv+ucBzww6R1V+0ujmfH-dED8XJhyRvWQF@mail.gmail.com","subject":"Re: [PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2011-02-08T18:23:29Z","receivedAt":"2011-02-08T18:23:29Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Tue, 8 Feb 2011, Sverre Rabbelier wrote:\n\n> Heya,\n> \n> On Tue, Feb 8, 2011 at 01:37, Martin von Zweigbergk\n> <martin.von.zweigbergk@gmail.com> wrote:\n> > Defaulting to @{upstream} will make it possible to run e.g. 'git\n> > rebase -i' without arguments, which is probably a quite common use\n> > case.\n> \n> I particularly like that you explain to the user clearly what they\n> have to do to make this work (e.g., configure the upstream). Nice.\n\nThanks, but that was stolen from git-pull.sh ;-). Federico Mena\nQuintero added it there in 8fc293c (Make git-pull complain and give\nadvice when there is nothing to merge with, 2007-10-02).\n\n/Martin\n"},{"id":"160708","messageId":"AANLkTikxz1FJcKRkqRHtm3hUfhbQkcWHnNT25Kws1+yi@mail.gmail.com","threadId":"26439","inReplyTo":"alpine.DEB.2.00.1102081320350.4475@debian","subject":"Re: [PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2011-02-08T18:27:03Z","receivedAt":"2011-02-08T18:27:03Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Tue, Feb 8, 2011 at 19:23, Martin von Zweigbergk\n<martin.von.zweigbergk@gmail.com> wrote:\n> Thanks, but that was stolen from git-pull.sh ;-). Federico Mena\n> Quintero added it there in 8fc293c (Make git-pull complain and give\n> advice when there is nothing to merge with, 2007-10-02).\n\nCredit where credit is due :), nonetheless, glad to see it here as well.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"160713","messageId":"20110208220505.GA17981@elie","threadId":"26439","inReplyTo":"alpine.DEB.2.00.1102081320350.4475@debian","subject":"Re: [PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-08T22:05:05Z","receivedAt":"2011-02-08T22:05:05Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Martin von Zweigbergk wrote:\n> On Tue, 8 Feb 2011, Sverre Rabbelier wrote:\n\n>> I particularly like that you explain to the user clearly what they\n>> have to do to make this work (e.g., configure the upstream). Nice.\n>\n> Thanks, but that was stolen from git-pull.sh ;-)\n\nDoesn't that suggest it might belong in some common git-upstream--lib.sh\n(or git-sh-setup.sh)?\n"},{"id":"160724","messageId":"alpine.DEB.2.00.1102081916330.9042@debian","threadId":"26439","inReplyTo":"20110208220505.GA17981@elie","subject":"Re: [PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2011-02-09T00:28:41Z","receivedAt":"2011-02-09T00:28:41Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Tue, 8 Feb 2011, Jonathan Nieder wrote:\n\n> Martin von Zweigbergk wrote:\n> > On Tue, 8 Feb 2011, Sverre Rabbelier wrote:\n> \n> >> I particularly like that you explain to the user clearly what they\n> >> have to do to make this work (e.g., configure the upstream). Nice.\n> >\n> > Thanks, but that was stolen from git-pull.sh ;-)\n> \n> Doesn't that suggest it might belong in some common git-upstream--lib.sh\n> (or git-sh-setup.sh)?\n\nMaybe it does... For comparison, I pasted the two sections below.\n\ngit-rebase.sh (after my patch):\n\n\tif test -z \"$branch_name\"\n\tthen\n\t\tdie \"You are not currently on a branch, so I cannot use any\n'branch.<branchname>.merge' in your configuration file.\nPlease specify which upstream branch you want to use on the command\nline and try again (e.g. 'git rebase <upstream branch>').\nSee git-rebase(1) for details.\"\n\telse\n\t\tdie \"You asked me to rebase without telling me which branch you\nwant to rebase against, and 'branch.${branch_name#refs/heads/}.merge' in\nyour configuration file does not tell me, either. Please\nspecify which branch you want to use on the command line and\ntry again (e.g. 'git rebase <upstream branch>').\nSee git-rebase(1) for details.\"\n\tfi\n\ngit-pull.sh:\n\n\telif [ -z \"$curr_branch\" ]; then\n\t\techo \"You are not currently on a branch, so I cannot use any\"\n\t\techo \"'branch.<branchname>.merge' in your configuration file.\"\n\t\techo \"Please specify which remote branch you want to use on the command\"\n\t\techo \"line and try again (e.g. 'git pull <repository> <refspec>').\"\n\t\techo \"See git-pull(1) for details.\"\n\telif [ -z \"$upstream\" ]; then\n\t\techo \"You asked me to pull without telling me which branch you\"\n\t\techo \"want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in\"\n\t\techo \"your configuration file does not tell me, either. Please\"\n\t\techo \"specify which branch you want to use on the command line and\"\n\t\techo \"try again (e.g. 'git pull <repository> <refspec>').\"\n\t\techo \"See git-pull(1) for details.\"\n\t\techo\n\t\techo \"If you often $op_type $op_prep the same branch, you may want to\"\n\t\techo \"use something like the following in your configuration file:\"\n\t\techo\n\t\techo \"    [branch \\\"${curr_branch}\\\"]\"\n\t\techo \"    remote = <nickname>\"\n\t\techo \"    merge = <remote-ref>\"\n\t\ttest rebase = \"$op_type\" &&\n\t\t\techo \"    rebase = true\"\n\t\techo\n\t\techo \"    [remote \\\"<nickname>\\\"]\"\n\t\techo \"    url = <url>\"\n\t\techo \"    fetch = <refspec>\"\n\t\techo\n\t\techo \"See git-config(1) for details.\"\n\n\nI had forgotten that I trimmed the last part of it. Maybe I should\nhave also included that? Then it would make even more sense to extract\nthis piece of code.\n\n\n/Martin\n"},{"id":"160730","messageId":"alpine.DEB.2.00.1102081959210.14152@debian","threadId":"26439","inReplyTo":"alpine.DEB.2.00.1102081916330.9042@debian","subject":"Re: [PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2011-02-09T01:50:31Z","receivedAt":"2011-02-09T01:50:31Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Tue, 8 Feb 2011, Martin von Zweigbergk wrote:\n\n> On Tue, 8 Feb 2011, Jonathan Nieder wrote:\n> \n> > Martin von Zweigbergk wrote:\n> > > On Tue, 8 Feb 2011, Sverre Rabbelier wrote:\n> > \n> > >> I particularly like that you explain to the user clearly what they\n> > >> have to do to make this work (e.g., configure the upstream). Nice.\n> > >\n> > > Thanks, but that was stolen from git-pull.sh ;-)\n> > \n> > Doesn't that suggest it might belong in some common git-upstream--lib.sh\n> > (or git-sh-setup.sh)?\n> \n> Maybe it does...\n\nMaybe something like this on top? I put it in git-parse-remote.sh for\nnow. There were some related functions there, so maybe it's not so\nbad. Should I put it there (and rename to git-upstream--lib.sh?), in\nnew git-upstream--lib.sh or in git-sh-setup.sh.\n\nChanges to the text compared to before:\n\n * \"remote branch\" became \"upstream branch\", even for git pull\n\n * \"You asked me to pull\" became \"You asked me to merge\" or \"You asked\n   me to rebase\", even for git pull\n\n * Now printed to stderr, because I simply didn't think about it. Good\n   or bad?\n\nWhat do you think?\n\n\n-- 8< --\n\n\ndiff --git a/git-parse-remote.sh b/git-parse-remote.sh\nindex 1cc2ba6..ff58d5b 100644\n--- a/git-parse-remote.sh\n+++ b/git-parse-remote.sh\n@@ -99,3 +99,40 @@ get_remote_merge_branch () {\n \t    esac\n \tesac\n }\n+\n+error_on_missing_default_upstream () {\n+\top_type=\"$1\"\n+\top_prep=\"$2\"\n+\texample=\"$3\"\n+\tdocumentation=\"$4\"\n+\tbranch_name=$(git symbolic-ref -q HEAD)\n+\tif test -z \"$branch_name\"\n+\tthen\n+\t\tdie \"You are not currently on a branch, so I cannot use any\n+'branch.<branchname>.merge' in your configuration file.\n+Please specify which upstream branch you want to use on the command\n+line and try again (e.g. '$example').\n+See $documentation for details.\"\n+\telse\n+\t\techo &2> \"You asked me to $op_type without telling me which branch you\n+want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in\n+your configuration file does not tell me, either. Please\n+specify which branch you want to use on the command line and\n+try again (e.g. '$example').\n+See $documentation for details.\n+\n+If you often $op_type $op_prep the same branch, you may want to\n+use something like the following in your configuration file:\n+    [branch \\\"${branch_name#refs/heads/}\\\"]\n+    remote = <nickname>\n+    merge = <remote-ref>\"\n+\t\ttest rebase = \"$op_type\" &&\n+\t\techo &2> \"    rebase = true\"\n+\t\tdie \"\n+    [remote \\\"<nickname>\\\"]\n+    url = <url>\n+    fetch = <refspec>\n+\n+See git-config(1) for details.\"\n+\tfi\n+}\ndiff --git a/git-pull.sh b/git-pull.sh\nindex eb87f49..8ec1d3d 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -163,34 +163,10 @@ error_on_no_merge_candidates () {\n \t\techo \"You asked to pull from the remote '$1', but did not specify\"\n \t\techo \"a branch. Because this is not the default configured remote\"\n \t\techo \"for your current branch, you must specify a branch on the command line.\"\n-\telif [ -z \"$curr_branch\" ]; then\n-\t\techo \"You are not currently on a branch, so I cannot use any\"\n-\t\techo \"'branch.<branchname>.merge' in your configuration file.\"\n-\t\techo \"Please specify which remote branch you want to use on the command\"\n-\t\techo \"line and try again (e.g. 'git pull <repository> <refspec>').\"\n-\t\techo \"See git-pull(1) for details.\"\n-\telif [ -z \"$upstream\" ]; then\n-\t\techo \"You asked me to pull without telling me which branch you\"\n-\t\techo \"want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in\"\n-\t\techo \"your configuration file does not tell me, either. Please\"\n-\t\techo \"specify which branch you want to use on the command line and\"\n-\t\techo \"try again (e.g. 'git pull <repository> <refspec>').\"\n-\t\techo \"See git-pull(1) for details.\"\n-\t\techo\n-\t\techo \"If you often $op_type $op_prep the same branch, you may want to\"\n-\t\techo \"use something like the following in your configuration file:\"\n-\t\techo\n-\t\techo \"    [branch \\\"${curr_branch}\\\"]\"\n-\t\techo \"    remote = <nickname>\"\n-\t\techo \"    merge = <remote-ref>\"\n-\t\ttest rebase = \"$op_type\" &&\n-\t\t\techo \"    rebase = true\"\n-\t\techo\n-\t\techo \"    [remote \\\"<nickname>\\\"]\"\n-\t\techo \"    url = <url>\"\n-\t\techo \"    fetch = <refspec>\"\n-\t\techo\n-\t\techo \"See git-config(1) for details.\"\n+\telif [ -z \"$curr_branch\" -o -z \"$upstream\" ]; then\n+\t\t. git-parse-remote\n+\t\terror_on_missing_default_upstream $op_type $op_prep \\\n+\t\t\t\"git pull <repository> <refspec>\" \"git-pull(1)\"\n \telse\n \t\techo \"Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'\"\n \t\techo \"from the remote, but no such ref was fetched.\"\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 5975642..8b39cab 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -144,25 +144,6 @@ run_pre_rebase_hook () {\n \tfi\n }\n \n-error_on_missing_default_upstream () {\n-\tbranch_name=$(git symbolic-ref -q HEAD)\n-\tif test -z \"$branch_name\"\n-\tthen\n-\t\tdie \"You are not currently on a branch, so I cannot use any\n-'branch.<branchname>.merge' in your configuration file.\n-Please specify which upstream branch you want to use on the command\n-line and try again (e.g. 'git rebase <upstream branch>').\n-See git-rebase(1) for details.\"\n-\telse\n-\t\tdie \"You asked me to rebase without telling me which branch you\n-want to rebase against, and 'branch.${branch_name#refs/heads/}.merge' in\n-your configuration file does not tell me, either. Please\n-specify which branch you want to use on the command line and\n-try again (e.g. 'git rebase <upstream branch>').\n-See git-rebase(1) for details.\"\n-\tfi\n-}\n-\n test -f \"$apply_dir\"/applying &&\n \tdie 'It looks like git-am is in progress. Cannot rebase.'\n \n@@ -381,8 +362,13 @@ if test -z \"$rebase_root\"\n then\n \tcase \"$#\" in\n \t0)\n-\t\tupstream_name=$(git rev-parse --symbolic-full-name --verify -q \\\n-\t\t@{upstream}) || error_on_missing_default_upstream\n+\t\tif ! upstream_name=$(git rev-parse --symbolic-full-name \\\n+\t\t\t--verify -q @{upstream})\n+\t\tthen\n+\t\t\t. git-parse-remote\n+\t\t\terror_on_missing_default_upstream \"rebase\" \"against\" \\\n+\t\t\t\t\"git rebase <upstream branch>\" \"git-rebase(1)\"\n+\t\tfi\n \t\t;;\n \t*)\tupstream_name=\"$1\"\n \t\tshift\n"},{"id":"160733","messageId":"20110209041737.GD24346@elie","threadId":"26439","inReplyTo":"alpine.DEB.2.00.1102081959210.14152@debian","subject":"Re: [PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-09T04:17:37Z","receivedAt":"2011-02-09T04:17:37Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Martin von Zweigbergk wrote:\n\n> Maybe something like this on top? I put it in git-parse-remote.sh for\n> now.\n\nThanks.  That sounds like a good place.\n\n> Changes to the text compared to before:\n>\n>  * \"remote branch\" became \"upstream branch\", even for git pull\n\nSensible for pull --rebase.  I'm not so sure about plain pull --- what\nif I am upstream and pulling from downstream?\n\n>  * \"You asked me to pull\" became \"You asked me to merge\" or \"You asked\n>    me to rebase\", even for git pull\n\n\"To pull\" would be clearer if the reader is new and unfamiliar with\nthe details.\n\n>  * Now printed to stderr, because I simply didn't think about it. Good\n>    or bad?\n\nIf this were a new message, I'd say stderr is better.\n\nAs is, the change to stderr seems relatively harmless, though I haven't\nthought about it deeply.  But a part of me likes to see functional\nchanges isolated in separate commits to make tracking down bugs a\nlittle easier.\n\nHope that helps,\nJonathan\n"},{"id":"160802","messageId":"alpine.DEB.2.00.1102092005300.20937@debian","threadId":"26439","inReplyTo":"20110209041737.GD24346@elie","subject":"Re: [PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2011-02-10T01:15:20Z","receivedAt":"2011-02-10T01:15:20Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Tue, 8 Feb 2011, Jonathan Nieder wrote:\n\n> Martin von Zweigbergk wrote:\n> \n> > Changes to the text compared to before:\n> >\n> >  * \"remote branch\" became \"upstream branch\", even for git pull\n> \n> Sensible for pull --rebase.  I'm not so sure about plain pull --- what\n> if I am upstream and pulling from downstream?\n> \n> >  * \"You asked me to pull\" became \"You asked me to merge\" or \"You asked\n> >    me to rebase\", even for git pull\n> \n> \"To pull\" would be clearer if the reader is new and unfamiliar with\n> the details.\n> \n> >  * Now printed to stderr, because I simply didn't think about it. Good\n> >    or bad?\n> \n> If this were a new message, I'd say stderr is better.\n> \n> As is, the change to stderr seems relatively harmless, though I haven't\n> thought about it deeply.  But a part of me likes to see functional\n> changes isolated in separate commits to make tracking down bugs a\n> little easier.\n\nThe patch below should address all of the above. See how you like the\nnew wording. The patch applies on top of the previous one to make the\nchanges clear. I will send a re-roll with all three patches squashed\nsoon as well.\n\nNote that this patch makes the test cases introduced in the original\npatch fail because of the error messages from 'git rebase' are now\nwritten to stdout. I will of course fix that in the re-roll.\n\nThanks for reviewing.\n\n/Martin\n\n\n-- 8< --\n\ndiff --git a/git-parse-remote.sh b/git-parse-remote.sh\nindex ff58d5b..be17ecb 100644\n--- a/git-parse-remote.sh\n+++ b/git-parse-remote.sh\n@@ -101,25 +101,25 @@ get_remote_merge_branch () {\n }\n \n error_on_missing_default_upstream () {\n-\top_type=\"$1\"\n-\top_prep=\"$2\"\n-\texample=\"$3\"\n-\tdocumentation=\"$4\"\n+\tcmd=\"$1\"\n+\top_type=\"$2\"\n+\top_prep=\"$3\"\n+\texample=\"$4\"\n \tbranch_name=$(git symbolic-ref -q HEAD)\n \tif test -z \"$branch_name\"\n \tthen\n-\t\tdie \"You are not currently on a branch, so I cannot use any\n+\t\techo \"You are not currently on a branch, so I cannot use any\n 'branch.<branchname>.merge' in your configuration file.\n-Please specify which upstream branch you want to use on the command\n+Please specify which branch you want to $op_type $op_prep on the command\n line and try again (e.g. '$example').\n-See $documentation for details.\"\n+See git-${cmd}(1) for details.\"\n \telse\n-\t\techo &2> \"You asked me to $op_type without telling me which branch you\n+\t\techo \"You asked me to $cmd without telling me which branch you\n want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in\n your configuration file does not tell me, either. Please\n specify which branch you want to use on the command line and\n try again (e.g. '$example').\n-See $documentation for details.\n+See git-${cmd}(1) for details.\n \n If you often $op_type $op_prep the same branch, you may want to\n use something like the following in your configuration file:\n@@ -127,12 +127,13 @@ use something like the following in your configuration file:\n     remote = <nickname>\n     merge = <remote-ref>\"\n \t\ttest rebase = \"$op_type\" &&\n-\t\techo &2> \"    rebase = true\"\n-\t\tdie \"\n+\t\techo \"    rebase = true\"\n+\t\techo \"\n     [remote \\\"<nickname>\\\"]\n     url = <url>\n     fetch = <refspec>\n \n See git-config(1) for details.\"\n \tfi\n+\texit 1\n }\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 8ec1d3d..2cdea26 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -165,8 +165,8 @@ error_on_no_merge_candidates () {\n \t\techo \"for your current branch, you must specify a branch on the command line.\"\n \telif [ -z \"$curr_branch\" -o -z \"$upstream\" ]; then\n \t\t. git-parse-remote\n-\t\terror_on_missing_default_upstream $op_type $op_prep \\\n-\t\t\t\"git pull <repository> <refspec>\" \"git-pull(1)\"\n+\t\terror_on_missing_default_upstream \"pull\" $op_type $op_prep \\\n+\t\t\t\"git pull <repository> <refspec>\"\n \telse\n \t\techo \"Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'\"\n \t\techo \"from the remote, but no such ref was fetched.\"\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 8b39cab..cff7aaa 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -366,8 +366,8 @@ then\n \t\t\t--verify -q @{upstream})\n \t\tthen\n \t\t\t. git-parse-remote\n-\t\t\terror_on_missing_default_upstream \"rebase\" \"against\" \\\n-\t\t\t\t\"git rebase <upstream branch>\" \"git-rebase(1)\"\n+\t\t\terror_on_missing_default_upstream \"rebase\" \"rebase\" \\\n+\t\t\t\t\"against\" \"git rebase <upstream branch>\"\n \t\tfi\n \t\t;;\n \t*)\tupstream_name=\"$1\"\n"},{"id":"160803","messageId":"1297302842-11296-1-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"26439","inReplyTo":"1297125475-19151-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2011-02-10T01:54:02Z","receivedAt":"2011-02-10T01:54:02Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"'git rebase' without arguments is currently not supported. Make it\ndefault to 'git rebase @{upstream}'. That is also what 'git pull\n[--rebase]' defaults to, so it only makes sense that 'git rebase'\ndefaults to the same thing.\n\nDefaulting to @{upstream} will make it possible to run e.g. 'git\nrebase -i' without arguments, which is probably a quite common use\ncase. It also improves the scenario where you have multiple branches\nthat rebase against a remote-tracking branch, where you currently have\nto choose between the extra network delay of 'git pull' or the\nslightly awkward keys to enter 'git rebase @{u}'.\n\nThe error reporting when no upstream is configured for the current\nbranch or when no branch is checked out is reused from git-pull.sh. A\nfunction is extracted into git-parse-remote.sh for this purpose.\n\nHelped-by: Yann Dirson <ydirson@altern.org>\nHelped-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n\nChanges since v1:\n\n * Extracted error reporting shared with git-pull.sh as suggested by\n   Jonathan.\n\n * Now discards stderr from \"git rev-parse -q @{upstream}\", since it's\n   not quite quiet when there is no upstream.\n\n\n Documentation/config.txt     |    2 +-\n Documentation/git-rebase.txt |   11 +++++++++--\n git-parse-remote.sh          |   38 ++++++++++++++++++++++++++++++++++++++\n git-pull.sh                  |   32 ++++----------------------------\n git-rebase.sh                |   21 +++++++++++++++------\n t/t3400-rebase.sh            |   27 ++++++++++++++++++---------\n 6 files changed, 85 insertions(+), 46 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex c5e1835..b4e65b8 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -646,7 +646,7 @@ branch.<name>.remote::\n \n branch.<name>.merge::\n \tDefines, together with branch.<name>.remote, the upstream branch\n-\tfor the given branch. It tells 'git fetch'/'git pull' which\n+\tfor the given branch. It tells 'git fetch'/'git pull'/'git rebase' which\n \tbranch to merge and can also affect 'git push' (see push.default).\n \tWhen in branch <name>, it tells 'git fetch' the default\n \trefspec to be marked for merging in FETCH_HEAD. The value is\ndiff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt\nindex 96680c8..d3e998d 100644\n--- a/Documentation/git-rebase.txt\n+++ b/Documentation/git-rebase.txt\n@@ -9,7 +9,7 @@ SYNOPSIS\n --------\n [verse]\n 'git rebase' [-i | --interactive] [options] [--onto <newbase>]\n-\t<upstream> [<branch>]\n+\t[<upstream>] [<branch>]\n 'git rebase' [-i | --interactive] [options] --onto <newbase>\n \t--root [<branch>]\n \n@@ -21,6 +21,12 @@ If <branch> is specified, 'git rebase' will perform an automatic\n `git checkout <branch>` before doing anything else.  Otherwise\n it remains on the current branch.\n \n+If <upstream> is not specified, the upstream configured in\n+branch.<name>.remote and branch.<name>.merge options will be used; see\n+linkgit:git-config[1] for details.  If you are currently not on any\n+branch or if the current branch does not have a configured upstream,\n+the rebase will abort.\n+\n All changes made by commits in the current branch but that are not\n in <upstream> are saved to a temporary area.  This is the same set\n of commits that would be shown by `git log <upstream>..HEAD` (or\n@@ -216,7 +222,8 @@ leave out at most one of A and B, in which case it defaults to HEAD.\n \n <upstream>::\n \tUpstream branch to compare against.  May be any valid commit,\n-\tnot just an existing branch name.\n+\tnot just an existing branch name. Defaults to the configured\n+\tupstream for the current branch.\n \n <branch>::\n \tWorking branch; defaults to HEAD.\ndiff --git a/git-parse-remote.sh b/git-parse-remote.sh\nindex 1cc2ba6..be17ecb 100644\n--- a/git-parse-remote.sh\n+++ b/git-parse-remote.sh\n@@ -99,3 +99,41 @@ get_remote_merge_branch () {\n \t    esac\n \tesac\n }\n+\n+error_on_missing_default_upstream () {\n+\tcmd=\"$1\"\n+\top_type=\"$2\"\n+\top_prep=\"$3\"\n+\texample=\"$4\"\n+\tbranch_name=$(git symbolic-ref -q HEAD)\n+\tif test -z \"$branch_name\"\n+\tthen\n+\t\techo \"You are not currently on a branch, so I cannot use any\n+'branch.<branchname>.merge' in your configuration file.\n+Please specify which branch you want to $op_type $op_prep on the command\n+line and try again (e.g. '$example').\n+See git-${cmd}(1) for details.\"\n+\telse\n+\t\techo \"You asked me to $cmd without telling me which branch you\n+want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in\n+your configuration file does not tell me, either. Please\n+specify which branch you want to use on the command line and\n+try again (e.g. '$example').\n+See git-${cmd}(1) for details.\n+\n+If you often $op_type $op_prep the same branch, you may want to\n+use something like the following in your configuration file:\n+    [branch \\\"${branch_name#refs/heads/}\\\"]\n+    remote = <nickname>\n+    merge = <remote-ref>\"\n+\t\ttest rebase = \"$op_type\" &&\n+\t\techo \"    rebase = true\"\n+\t\techo \"\n+    [remote \\\"<nickname>\\\"]\n+    url = <url>\n+    fetch = <refspec>\n+\n+See git-config(1) for details.\"\n+\tfi\n+\texit 1\n+}\ndiff --git a/git-pull.sh b/git-pull.sh\nindex eb87f49..2cdea26 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -163,34 +163,10 @@ error_on_no_merge_candidates () {\n \t\techo \"You asked to pull from the remote '$1', but did not specify\"\n \t\techo \"a branch. Because this is not the default configured remote\"\n \t\techo \"for your current branch, you must specify a branch on the command line.\"\n-\telif [ -z \"$curr_branch\" ]; then\n-\t\techo \"You are not currently on a branch, so I cannot use any\"\n-\t\techo \"'branch.<branchname>.merge' in your configuration file.\"\n-\t\techo \"Please specify which remote branch you want to use on the command\"\n-\t\techo \"line and try again (e.g. 'git pull <repository> <refspec>').\"\n-\t\techo \"See git-pull(1) for details.\"\n-\telif [ -z \"$upstream\" ]; then\n-\t\techo \"You asked me to pull without telling me which branch you\"\n-\t\techo \"want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in\"\n-\t\techo \"your configuration file does not tell me, either. Please\"\n-\t\techo \"specify which branch you want to use on the command line and\"\n-\t\techo \"try again (e.g. 'git pull <repository> <refspec>').\"\n-\t\techo \"See git-pull(1) for details.\"\n-\t\techo\n-\t\techo \"If you often $op_type $op_prep the same branch, you may want to\"\n-\t\techo \"use something like the following in your configuration file:\"\n-\t\techo\n-\t\techo \"    [branch \\\"${curr_branch}\\\"]\"\n-\t\techo \"    remote = <nickname>\"\n-\t\techo \"    merge = <remote-ref>\"\n-\t\ttest rebase = \"$op_type\" &&\n-\t\t\techo \"    rebase = true\"\n-\t\techo\n-\t\techo \"    [remote \\\"<nickname>\\\"]\"\n-\t\techo \"    url = <url>\"\n-\t\techo \"    fetch = <refspec>\"\n-\t\techo\n-\t\techo \"See git-config(1) for details.\"\n+\telif [ -z \"$curr_branch\" -o -z \"$upstream\" ]; then\n+\t\t. git-parse-remote\n+\t\terror_on_missing_default_upstream \"pull\" $op_type $op_prep \\\n+\t\t\t\"git pull <repository> <refspec>\"\n \telse\n \t\techo \"Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'\"\n \t\techo \"from the remote, but no such ref was fetched.\"\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex be9ec2a..a040ab5 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -3,7 +3,7 @@\n # Copyright (c) 2005 Junio C Hamano.\n #\n \n-USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] (<upstream>|--root) [<branch>] [--quiet | -q]'\n+USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]'\n LONG_USAGE='git-rebase replaces <branch> with a new branch of the\n same name.  When the --onto option is provided the new branch starts\n out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>\n@@ -345,8 +345,6 @@ and run me again.  I am stopping in case you still have something\n valuable there.'\n fi\n \n-test $# -eq 0 && test -z \"$rebase_root\" && usage\n-\n if test -n \"$interactive_rebase\"\n then\n \ttype=interactive\n@@ -362,9 +360,20 @@ fi\n \n if test -z \"$rebase_root\"\n then\n-\t# The upstream head must be given.  Make sure it is valid.\n-\tupstream_name=\"$1\"\n-\tshift\n+\tcase \"$#\" in\n+\t0)\n+\t\tif ! upstream_name=$(git rev-parse --symbolic-full-name \\\n+\t\t\t--verify -q @{upstream} 2>/dev/null)\n+\t\tthen\n+\t\t\t. git-parse-remote\n+\t\t\terror_on_missing_default_upstream \"rebase\" \"rebase\" \\\n+\t\t\t\t\"against\" \"git rebase <upstream branch>\"\n+\t\tfi\n+\t\t;;\n+\t*)\tupstream_name=\"$1\"\n+\t\tshift\n+\t\t;;\n+\tesac\n \tupstream=`git rev-parse --verify \"${upstream_name}^0\"` ||\n \tdie \"invalid upstream $upstream_name\"\n \tupstream_arg=\"$upstream_name\"\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex 349eebd..6eaecec 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -158,15 +158,24 @@ test_expect_success 'Show verbose error when HEAD could not be detached' '\n '\n rm -f B\n \n-test_expect_success 'dump usage when upstream arg is missing' '\n-\tgit checkout -b usage topic &&\n-\ttest_must_fail git rebase 2>error1 &&\n-\tgrep \"[Uu]sage\" error1 &&\n-\ttest_must_fail git rebase --abort 2>error2 &&\n-\tgrep \"No rebase in progress\" error2 &&\n-\ttest_must_fail git rebase --onto master 2>error3 &&\n-\tgrep \"[Uu]sage\" error3 &&\n-\t! grep \"can.t shift\" error3\n+test_expect_success 'fail when upstream arg is missing and not on branch' '\n+\tgit checkout topic &&\n+\ttest_must_fail git rebase >output.out &&\n+\tgrep \"You are not currently on a branch\" output.out\n+'\n+\n+test_expect_success 'fail when upstream arg is missing and not configured' '\n+\tgit checkout -b no-config topic &&\n+\ttest_must_fail git rebase >output.out &&\n+\tgrep \"branch.no-config.merge\" output.out\n+'\n+\n+test_expect_success 'default to @{upstream} when upstream arg is missing' '\n+\tgit checkout -b default topic &&\n+\tgit config branch.default.remote .\n+\tgit config branch.default.merge refs/heads/master\n+\tgit rebase &&\n+\ttest \"$(git rev-parse default~1)\" = \"$(git rev-parse master)\"\n '\n \n test_expect_success 'rebase -q is quiet' '\n-- \n1.7.4.rc2.33.g8a14f\n"},{"id":"160806","messageId":"7voc6k62xq.fsf@alter.siamese.dyndns.org","threadId":"26439","inReplyTo":"1297302842-11296-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"Re: [PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-10T02:25:37Z","receivedAt":"2011-02-10T02:25:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:\n\n> 'git rebase' without arguments is currently not supported. Make it\n> default to 'git rebase @{upstream}'. That is also what 'git pull\n> [--rebase]' defaults to, so it only makes sense that 'git rebase'\n> defaults to the same thing.\n\nNot that I am fundamentally opposed to the proposed change, but the above is\nnot a very convincing argument, when the corresponding change to \"git merge\"\nis just started getting discussed.\n\nOn top of what commit does this patch apply, by the way?\n"},{"id":"160810","messageId":"alpine.DEB.2.00.1102092136580.20937@debian","threadId":"26439","inReplyTo":"7voc6k62xq.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] rebase: use @{upstream} if no upstream specified","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2011-02-10T02:46:14Z","receivedAt":"2011-02-10T02:46:14Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Wed, 9 Feb 2011, Junio C Hamano wrote:\n\n> Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:\n> \n> > 'git rebase' without arguments is currently not supported. Make it\n> > default to 'git rebase @{upstream}'. That is also what 'git pull\n> > [--rebase]' defaults to, so it only makes sense that 'git rebase'\n> > defaults to the same thing.\n> \n> Not that I am fundamentally opposed to the proposed change, but the above is\n> not a very convincing argument, when the corresponding change to \"git merge\"\n> is just started getting discussed.\n\nThere was a little more motivation later in the commit message, like\nusing it with 'git rebase -i'. I have been using it for a few months\nnow, and I also find it quite useful e.g. when rebasing all my\nbranches on top of your master.\n\n> \n> On top of what commit does this patch apply, by the way?\n\nOn top of the rebase refactoring series I posted a few days ago. See\nhttp://thread.gmane.org/gmane.comp.version-control.git/166161/.\n\n\n/Martin\n"}]}