Skip to content

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

@Mierdin

Description

@Mierdin

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions