Skip to content

Specify checkout target (tag, branch) when running #476

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

Closed
Mierdin opened this issue Jun 15, 2016 · 2 comments
Closed

Specify checkout target (tag, branch) when running #476

Mierdin opened this issue Jun 15, 2016 · 2 comments

Comments

@Mierdin
Copy link

Mierdin commented Jun 15, 2016

I'm having an issue with pulling a repo, and I'm pretty sure it has to do with me using a new version of either GitPython or Git (it worked previously).

Here's the relevant snippet:

# Attempt to read from repo on filesystem
repo = Repo(repo_dir)

# Trigger re-create if repository is bare
if repo.bare:
    raise git.exc.InvalidGitRepositoryError

# Set origin
origin = repo.remotes.origin
origin.pull()

In this case, I am trying to check out a git tag that already exists, and I want to run a "pull" to ensure I have the latest changes from that target. As I mentioned, it was working previously - but something changed, causing the following stack trace (which originates from that last line in the above example):

Traceback (most recent call last):
  File "/usr/lib/python2.7/<project>.py", line 44, in setup_repo
    origin.pull()
  File "/usr/local/lib/python2.7/dist-packages/git/remote.py", line 709, in pull
    res = self._get_fetch_info_from_stderr(proc, progress)
  File "/usr/local/lib/python2.7/dist-packages/git/remote.py", line 587, in _get_fetch_info_from_stderr
    finalize_process(proc)
  File "/usr/local/lib/python2.7/dist-packages/git/util.py", line 155, in finalize_process
    proc.wait(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 326, in wait
    raise GitCommandError(self.args, status, errstr)
GitCommandError: 'git pull -v origin' returned with exit code 1

Naturally, I ran the same command in that repo and get the same result:

vagrant@pythondev:/tmp/repo_dir/v0.0.0.26$ git pull -v origin
From < git remote >
 = [up to date]      master     -> origin/master
You asked to pull from the remote 'origin', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.

As provided in the error message, I just need to specify the tag like so: git pull -v origin v0.0.0.26. However, upon looking at what I believe is the source code behind the GitPython .pull() function, it's not clear if I am able to specify this argument to that function.

So, in summary, is there a way to specify the branch or tag that I wish to pull when I use the .pull() function? Thanks in advance!

@Mierdin
Copy link
Author

Mierdin commented Jun 15, 2016

WOW - I feel quite silly about missing the "refspec" argument right there in the function definition. It's the first argument! Easily fixed by simply changing the "pull" line to:

origin.pull("v0.0.0.26")

A big nevermind on this! I would say that I feel this is a reasonably common operation, so while this is certainly well documented in the API docs, it may be worth adding this as a brief example to the tutorial.

@Mierdin Mierdin closed this as completed Jun 15, 2016
@Byron
Copy link
Member

Byron commented Jun 20, 2016

Great to hear this worked out for you :) (and sorry for the late reply).

You are probably right, certain things could be made clearer in the tutorial. Considering you ran into this, you should be the one to know best what would have helped you.
Therefore, if you would like to submit a PR, I will be here to merge it.
Thanks and cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants