Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: make update work consistently for git #2109

Closed
adg opened this issue Jul 26, 2011 · 8 comments
Closed

cmd/go: make update work consistently for git #2109

adg opened this issue Jul 26, 2011 · 8 comments
Milestone

Comments

@adg
Copy link
Contributor

adg commented Jul 26, 2011

as per: https://groups.google.com/d/msg/golang-nuts/3GtbT2s2HCc/djHr2YXFzEQJ

--

I do not think "goinstall -u" does what its author intended. It does this:

git fetch
git show-ref release
git checkout release

"git fetch" does not alter "release". It alters
"origin/release" (along with other branches, on all remotes: "man
git-remote"). You need to follow-up with

git merge FETCH_HEAD

to do a true update, assuming that the branch is actually tracking something. For
details:

http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html
http://git.661346.n2.nabble.com/FETCH-HEAD-question-td2339060.html

But merging can me a mess. I have a better idea:

git fetch origin  # to avoid wasting time on other remotes
git show-ref origin/release
git checkout origin/release

"origin" is ok, since goinstall implicitly created the remote with that name
when it cloned the repo. You would then see

$ git branch
* (no branch)
  master
  release

"(no branch)" is explained here:
http://edspencer.net/2009/10/git-what-to-do-if-you-commit-to-no-branch.html
Generally, you never commit to "no branch". The "origin/release"
thing is a pseudo-branch, technically a "remote tracking branch". You cannot
alter its head; it just tracks the remote when you "fetch". No merging is
necessary.

The other benefit is that I can change which remote "origin" refers to, as I
just described in another post.

goinstall -v github.com/blah/blah/blah
cd gopath-dir/src/github.com/blah/blah/blah
git remote rename origin official  # official/release is the official branch now.
git remote add origin git://~me/path
git fetch origin
git branch --set-upstream release origin/release
goinstall -v -u github.com/blah/blah/blah

At that point, "-u" will fetch from my own github repo. (And currently, it
will change me to the "release" branch, but fail to merge from
"origin/release". I hope that's clear.)
Report abusePost reply
@gopherbot
Copy link

Comment 1 by cdunn2001:

Tarmigan writes:
> This doesn't solve the merging issue though, because if you have uncommitted changes
in your working tree, they could be lost in checking out the detached HEAD, so git may
complain and refuse the checkout.
That's what I want it to do. If the local changes are compatible, the operation
succeeds, and the file remains changed. If they are not compatible, I get this message:
$ git checkout origin/release
error: Your local changes to the following files would be overwritten by checkout:
        skygen/skygen.go
Please, commit your changes or stash them before you can switch branches.
That's exactly what I want to see, since I changed a file locally that was also changed
in the repo. The merge would fail too. I'd be more concerned about furtive merges that
do *not* fail.

@gopherbot
Copy link

Comment 2 by cdunn2001:

On the other hand, if you really want to go the "merge" route, I hope you will at least
consider a "fast-forward only" merge,
    git merge --ff-only FETCH_HEAD
for some safety.

@adg
Copy link
Contributor Author

adg commented Oct 17, 2011

Comment 3:

Git is way too complicated.

Owner changed to ---.

Status changed to HelpWanted.

@rsc
Copy link
Contributor

rsc commented Dec 9, 2011

Comment 4:

Labels changed: added priority-later.

@rsc
Copy link
Contributor

rsc commented Dec 12, 2011

Comment 5:

Labels changed: added priority-go1.

@robpike
Copy link
Contributor

robpike commented Jan 13, 2012

Comment 6:

Owner changed to builder@golang.org.

@rsc
Copy link
Contributor

rsc commented Jan 30, 2012

Comment 8:

Labels changed: added go1-must.

@rsc
Copy link
Contributor

rsc commented Jan 31, 2012

Comment 9:

This issue was closed by revision 0f10566.

Status changed to Fixed.

@adg adg added fixed labels Jan 31, 2012
@rsc rsc added this to the Go1 milestone Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants