From: Garrett Cooper <hidden> Date: 2016-06-15 22:56:36
Hi!
It looks like git branch --set-upstream-to doesn't function with 1.8.1.3 until I run --set-upstream. Is this a known bug?
root@fuji-current:/usr/src # git branch --set-upstream-to origin/pjdfstest-onefs pjdfstest-onefs
fatal: Not a valid object name: 'origin/pjdfstest-onefs'.
root@fuji-current:/usr/src # git branch --set-upstream origin/pjdfstest-onefs pjdfstest-onefs
The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
Branch origin/pjdfstest-onefs set up to track local branch pjdfstest-onefs.
root@fuji-current:/usr/src # git branch --set-upstream-to origin/pjdfstest-onefs pjdfstest-onefs
Branch pjdfstest-onefs set up to track local branch origin/pjdfstest-onefs.
root@fuji-current:/usr/src # git --version
git version 1.8.1.3
Thanks!
-Garrett
PS Please CC me as I'm not subscribed to the list.
From: Jeff King <hidden> Date: 2016-06-15 22:56:36
On Tue, Apr 02, 2013 at 10:07:01AM -0700, Garrett Cooper wrote:
It looks like git branch --set-upstream-to doesn't function with 1.8.1.3 until I run --set-upstream. Is this a known bug?
No, but I do not think that is exactly what is going on.
root@fuji-current:/usr/src # git branch --set-upstream-to origin/pjdfstest-onefs pjdfstest-onefs
fatal: Not a valid object name: 'origin/pjdfstest-onefs'.
This is complaining that origin/pjdfstest-onefs does not actually exist
Does it? If the pjdfstest-onefs branch exists on the remote, do you need
to do a "git fetch" to make sure we have a local
refs/remotes/origin/pjdfstest-onefs tracking branch locally?
root@fuji-current:/usr/src # git branch --set-upstream origin/pjdfstest-onefs pjdfstest-onefs
The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
Branch origin/pjdfstest-onefs set up to track local branch pjdfstest-onefs.
This did _not_ create the remote-tracking branch refs/remotes/origin/pjdfstest-onefs.
It created a new local branch called "origin/pjdfstest-onefs" (i.e.,
refs/heads/origin/pjdfstest-onefs), whose upstream is another local
branch "pjdfstest-onefs". That "backwards" order to the arguments is why
--set-upstream is deprecated; many people have made the same mistake.
root@fuji-current:/usr/src # git branch --set-upstream-to origin/pjdfstest-onefs pjdfstest-onefs
Branch pjdfstest-onefs set up to track local branch origin/pjdfstest-onefs.
Note how it says "local branch" here; you are not tracking anything at
the origin. You are tracking a local branch that happens to have
"origin/" in the name.
-Peff
From: Garrett Cooper <hidden> Date: 2016-06-15 22:56:36
On Apr 2, 2013, at 10:23 AM, Jeff King [off-list ref] wrote:
On Tue, Apr 02, 2013 at 10:07:01AM -0700, Garrett Cooper wrote:
quoted
It looks like git branch --set-upstream-to doesn't function with 1.8.1.3 until I run --set-upstream. Is this a known bug?
No, but I do not think that is exactly what is going on.
quoted
root@fuji-current:/usr/src # git branch --set-upstream-to origin/pjdfstest-onefs pjdfstest-onefs
fatal: Not a valid object name: 'origin/pjdfstest-onefs'.
This is complaining that origin/pjdfstest-onefs does not actually exist
Does it? If the pjdfstest-onefs branch exists on the remote, do you need
to do a "git fetch" to make sure we have a local
refs/remotes/origin/pjdfstest-onefs tracking branch locally?
quoted
root@fuji-current:/usr/src # git branch --set-upstream origin/pjdfstest-onefs pjdfstest-onefs
The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
Branch origin/pjdfstest-onefs set up to track local branch pjdfstest-onefs.
This did _not_ create the remote-tracking branch refs/remotes/origin/pjdfstest-onefs.
It created a new local branch called "origin/pjdfstest-onefs" (i.e.,
refs/heads/origin/pjdfstest-onefs), whose upstream is another local
branch "pjdfstest-onefs". That "backwards" order to the arguments is why
--set-upstream is deprecated; many people have made the same mistake.
quoted
root@fuji-current:/usr/src # git branch --set-upstream-to origin/pjdfstest-onefs pjdfstest-onefs
Branch pjdfstest-onefs set up to track local branch origin/pjdfstest-onefs.
Note how it says "local branch" here; you are not tracking anything at
the origin. You are tracking a local branch that happens to have
"origin/" in the name.
I push the branch to origin/ and then things tend to work, but since I obviously had been doing things wrong what's the correct order of operations for creating a branch and setting the upstream appropriately?
Thanks!
-Garrett
PS I love git as a tool, but I really wish the workflows were simpler or more straightforward, and error messages were clearer. It seems like this would help prevent usage errors like this..
From: Jeff King <hidden> Date: 2016-06-15 22:56:36
On Tue, Apr 02, 2013 at 10:30:35AM -0700, Garrett Cooper wrote:
I push the branch to origin/ and then things tend to work, but since I
obviously had been doing things wrong what's the correct order of
operations for creating a branch and setting the upstream
appropriately?
Once you have pushed it, the push creates the refs/remotes/origin/foo
tracking branch automatically. You are then free to reference it
wherever you like, including in set-upstream-to. However, you can also
just ask push to do it for you with "--set-upstream" or "-u". So the
workflow is something like:
$ git checkout -b my-topic
$ hack hack hack
$ git commit -m "looking good, time to publish"
$ git push -u origin HEAD
PS I love git as a tool, but I really wish the workflows were simpler
or more straightforward, and error messages were clearer. It seems
like this would help prevent usage errors like this..
Things slowly improve as people make suggestions. I think the thing that
might have helped here is better advice when "set-upstream-to" is
pointed to a ref that does not exist.
Patches coming in a minute.
-Peff
From: Jeff King <hidden> Date: 2016-06-15 22:56:36
On Tue, Apr 02, 2013 at 01:51:13PM -0400, Jeff King wrote:
Things slowly improve as people make suggestions. I think the thing that
might have helped here is better advice when "set-upstream-to" is
pointed to a ref that does not exist.
Patches coming in a minute.
Or 60 minutes. :)
I'm not decided on whether the last patch is overkill or not (or even if
it is not, whether it may end up confusing people who do not fit into
one of the slots it suggests).
[1/5]: t3200: test --set-upstream-to with bogus refs
[2/5]: branch: factor out "upstream is not a branch" error messages
[3/5]: branch: improve error message for missing --set-upstream-to ref
[4/5]: branch: mention start_name in set-upstream error messages
[5/5]: branch: give advice when tracking start-point is missing
-Peff
From: Jeff King <hidden> Date: 2016-06-15 22:56:36
These tests pass with the current code, but let's make sure
we don't accidentally break the behavior in the future.
Note that our tests expect failure when we try to set the
upstream to or from a missing branch. Technically we are
just munging config here, so we do not need the refs to
exist. But seeing that they do exist is a good check that
the user has not made a typo.
Signed-off-by: Jeff King <redacted>
---
t/t3200-branch.sh | 12 ++++++++++++
1 file changed, 12 insertions(+)
@@ -409,6 +409,18 @@ test_expect_success '--set-upstream-to fails on detached HEAD' 'gitcheckout-'+test_expect_success'--set-upstream-to fails on a missing dst branch''+test_must_failgitbranch--set-upstream-tomasterdoes-not-exist+'++test_expect_success'--set-upstream-to fails on a missing src branch''+test_must_failgitbranch--set-upstream-todoes-not-existmaster+'++test_expect_success'--set-upstream-to fails on a non-ref''+test_must_failgitbranch--set-upstream-toHEAD^{}+'+ test_expect_success'use --set-upstream-to modify HEAD''test_configbranch.master.remotefoo&&test_configbranch.master.mergefoo&&
From: Jeff King <hidden> Date: 2016-06-15 22:56:36
This message is duplicated, and is quite long. Let's factor
it out, which avoids the repetition and the long lines. It
will also make future patches easier as we tweak the
message.
While we're at it, let's also mark it for translation.
Signed-off-by: Jeff King <redacted>
---
branch.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
@@ -197,6 +197,9 @@ int validate_new_branchname(const char *name, struct strbuf *ref,return1;}+staticconstcharupstream_not_branch[]=+N_("Cannot setup tracking information; starting point is not a branch.");+voidcreate_branch(constchar*head,constchar*name,constchar*start_name,intforce,intreflog,intclobber_head,
@@ -231,14 +234,14 @@ void create_branch(const char *head,case0:/* Not branching from any existing branch */if(explicit_tracking)-die("Cannot setup tracking information; starting point is not a branch.");+die(_(upstream_not_branch));break;case1:/* Unique completion -- good, only if it is a real branch */if(prefixcmp(real_ref,"refs/heads/")&&prefixcmp(real_ref,"refs/remotes/")){if(explicit_tracking)-die("Cannot setup tracking information; starting point is not a branch.");+die(_(upstream_not_branch));elsereal_ref=NULL;}
From: Jeff King <hidden> Date: 2016-06-15 22:56:36
If we are trying to set the upstream config for a branch,
the create_branch function will check both that the name
resolves as a ref, and that it is either a local or
remote-tracking branch.
However, before we do so we run get_sha1 on it to find out
whether it resolves at all (since the create_branch function
is also used to create actual branches, it wants to know
where to start the new branch). This means that if you feed
a ref that does not exist to "branch --set-upstream-to",
rather than getting a helpful message about tracking, you
only get "not a valid object name".
Signed-off-by: Jeff King <redacted>
---
branch.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
@@ -199,6 +199,8 @@ N_("Cannot setup tracking information; starting point is not a branch.");staticconstcharupstream_not_branch[]=N_("Cannot setup tracking information; starting point is not a branch.");+staticconstcharupstream_missing[]=+N_("Cannot setup tracking information; starting point does not exist");voidcreate_branch(constchar*head,constchar*name,constchar*start_name,
From: Jeff King <hidden> Date: 2016-06-15 22:56:36
If we refuse a branch operation because the tracking
start_name the user gave us is bogus, we just print
something like:
fatal: Cannot setup tracking information; start point is not a branch
If we mention the actual name we tried to use, that may help
the user figure out why it didn't work (e.g., if they gave
us the arguments in the wrong order).
Signed-off-by: Jeff King <redacted>
---
branch.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
@@ -198,9 +198,9 @@ static const char upstream_missing[] =}staticconstcharupstream_not_branch[]=-N_("Cannot setup tracking information; starting point is not a branch.");+N_("Cannot setup tracking information; starting point '%s' is not a branch.");staticconstcharupstream_missing[]=-N_("Cannot setup tracking information; starting point does not exist");+N_("Cannot setup tracking information; starting point '%s' does not exist");voidcreate_branch(constchar*head,constchar*name,constchar*start_name,
@@ -239,14 +239,14 @@ void create_branch(const char *head,case0:/* Not branching from any existing branch */if(explicit_tracking)-die(_(upstream_not_branch));+die(_(upstream_not_branch),start_name);break;case1:/* Unique completion -- good, only if it is a real branch */if(prefixcmp(real_ref,"refs/heads/")&&prefixcmp(real_ref,"refs/remotes/")){if(explicit_tracking)-die(_(upstream_not_branch));+die(_(upstream_not_branch),start_name);elsereal_ref=NULL;}
From: Jeff King <hidden> Date: 2016-06-15 22:56:36
If the user requests to --set-upstream-to a branch that does
not exist, then either:
1. It was a typo.
2. They thought the branch should exist.
In case (1), there is not much we can do beyond showing the
name we tried to use. For case (2), though, we can help to
guide them through common workflows.
Signed-off-by: Jeff King <redacted>
---
advice.c | 2 ++
advice.h | 1 +
branch.c | 19 +++++++++++++++++--
3 files changed, 20 insertions(+), 2 deletions(-)
@@ -13,6 +13,7 @@ int advice_detached_head = 1;intadvice_resolve_conflict=1;intadvice_implicit_identity=1;intadvice_detached_head=1;+intadvice_set_upstream_failure=1;staticstruct{constchar*name;
@@ -31,6 +32,7 @@ static struct {{"resolveconflict",&advice_resolve_conflict},{"implicitidentity",&advice_implicit_identity},{"detachedhead",&advice_detached_head},+{"setupstreamfailure",&advice_set_upstream_failure},/* make this an alias for backward compatibility */{"pushnonfastforward",&advice_push_update_rejected}
@@ -200,7 +200,16 @@ static const char upstream_missing[] =staticconstcharupstream_not_branch[]=N_("Cannot setup tracking information; starting point '%s' is not a branch.");staticconstcharupstream_missing[]=-N_("Cannot setup tracking information; starting point '%s' does not exist");+N_("the requested upstream branch '%s' does not exist");+staticconstcharupstream_advice[]=+N_("\n"+"If you are planning on basing your work on an upstream\n"+"branch that already exists at the remote, you may need to\n"+"run \"git fetch\" to retrieve it.\n"+"\n"+"If you are planning to push out a new local branch that\n"+"will track its remote counterpart, you may want to use\n"+"\"git push -u\" to set the upstream config as you push.");voidcreate_branch(constchar*head,constchar*name,constchar*start_name,
From: Jonathan Nieder <hidden> Date: 2016-06-15 22:56:37
Garrett Cooper wrote:
I push the branch to origin/ and then things tend to work, but since
I obviously had been doing things wrong what's the correct order of
operations for creating a branch and setting the upstream
appropriately?
git push -u origin pjdfstest-onefs
Thanks for a useful example,
Jonathan
From: Garrett Cooper <hidden> Date: 2016-06-15 22:56:37
On Tue, Apr 2, 2013 at 12:03 PM, Jeff King [off-list ref] wrote:
This message is duplicated, and is quite long. Let's factor
it out, which avoids the repetition and the long lines. It
will also make future patches easier as we tweak the
message.
While we're at it, let's also mark it for translation.
Signed-off-by: Jeff King <redacted>
From: Garrett Cooper <hidden> Date: 2016-06-15 22:56:37
On Tue, Apr 2, 2013 at 12:36 PM, Garrett Cooper [off-list ref] wrote:
On Tue, Apr 2, 2013 at 12:03 PM, Jeff King [off-list ref] wrote:
quoted
This message is duplicated, and is quite long. Let's factor
it out, which avoids the repetition and the long lines. It
will also make future patches easier as we tweak the
message.
While we're at it, let's also mark it for translation.
Signed-off-by: Jeff King <redacted>
LGTM!
Signed-off-by: Garrett Cooper <redacted>
Sorry, meant...
Reviewed-by: Garrett Cooper <redacted>
From: Garrett Cooper <hidden> Date: 2016-06-15 22:56:37
On Tue, Apr 2, 2013 at 12:04 PM, Jeff King [off-list ref] wrote:
If we refuse a branch operation because the tracking
start_name the user gave us is bogus, we just print
something like:
fatal: Cannot setup tracking information; start point is not a branch
If we mention the actual name we tried to use, that may help
the user figure out why it didn't work (e.g., if they gave
us the arguments in the wrong order).
Signed-off-by: Jeff King <redacted>