This week a user accidentally did this:
$ git push origin origin/master
Total 0 (delta 0), reused 0 (delta 0)
To parent.git
* [new branch] origin/master -> origin/master
He saw his mistake when the "new branch" message appeared, but he was
confused about how to fix it and worried he broke something.
It seems reasonable that git expanded the original args into this one:
git push origin refs/remotes/origin/master
However, since the dest ref was not provided, it was assumed to be the
same as the source ref, so it worked as if he typed this:
git push origin refs/remotes/origin/master:refs/remotes/origin/master
Indeed, git ls-remote origin shows the result:
$ git ls-remote origin
d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e HEAD
d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/heads/master
d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/remotes/origin/master
Also, I verified that this (otherwise valid) command has similar
unexpected results:
$ git remote add other foo.git && git fetch other && git push
origin other/topic
$ git ls-remote origin
d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e HEAD
d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/heads/master
d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/remotes/origin/master
d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/remotes/other/topic
I think git should be smarter about deducing the dest ref from the
source ref if the source ref is in refs/remotes, but I'm not sure how
far to take it. It feels like we should translate refspecs something
like this for push:
origin/master
=> refs/remotes/origin/master:refs/heads/master
refs/remotes/origin/master
=> refs/remotes/origin/master:refs/heads/master
origin/master:origin/master
=> refs/remotes/origin/master:refs/heads/origin/master
master:refs/remotes/origin/master
=> refs/heads/master:refs/remotes/origin/master
That is, we should not infer a remote refspec of "refs/remotes/*"; we
should only get there if "refs/remotes" was given explicitly by the
user.
Does this seem reasonable? I can try to work up a patch if so.