Skip to content

Repo.git.branch parsing broken #92

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
bilderbuchi opened this issue Jan 31, 2013 · 2 comments
Closed

Repo.git.branch parsing broken #92

bilderbuchi opened this issue Jan 31, 2013 · 2 comments
Assignees

Comments

@bilderbuchi
Copy link

Something must be broken in some Repo.git.* command argument parsing. In some git repo, do

import git
repo = git.Repo()
repo.git.branch('somebranch') # works
repo.git.checkout(b='otherbranch') # works
repo.git.branch(D='somebranch') # to force delete a branch, fails:
---------------------------------------------------------------------------
GitCommandError                           Traceback (most recent call last)
<ipython-input-6-bfd51b2d0b04> in <module>()
----> 1 repo.git.branch(D='somebranch')

/usr/lib/python2.7/dist-packages/git/cmd.pyc in <lambda>(*args, **kwargs)
    225                 if name[0] == '_':
    226                         return LazyMixin.__getattr__(self, name)
--> 227                 return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
    228 
    229         def _set_cache_(self, attr):

/usr/lib/python2.7/dist-packages/git/cmd.pyc in _call_process(self, method, *args, **kwargs)
    454                 call.extend(args)
    455 
--> 456                 return self.execute(call, **_kwargs)
    457 
    458         def _parse_object_header(self, header_line):

/usr/lib/python2.7/dist-packages/git/cmd.pyc in execute(self, command, istream, with_keep_cwd, with_extended_output, with_exceptions, as_process, output_stream, **subprocess_kwargs)
    375 
    376                 if with_exceptions and status != 0:
--> 377                         raise GitCommandError(command, status, stderr_value)
    378 
    379                 # Allow access to the command's status code

GitCommandError: 'git branch -Dsomebranch' returned exit status 129: error: unknown switch `s'
usage: git branch etc. etc...

from the GitCommandError you can see that for some reason, there's a space missing in the created git command.

git.__version__
Out[10]: '0.3.2 RC1'
@Byron Byron added this to the v0.3.5 - bugfixes milestone Nov 19, 2014
@Byron
Copy link
Member

Byron commented Nov 19, 2014

Usually this can be worked around by using the long version of a flag. In some cases, like -D there is no long version though.

@Byron Byron self-assigned this Jan 9, 2015
@Byron
Copy link
Member

Byron commented Jan 9, 2015

Especially the -D flag of git branch doesn't behave as the common posix flag parsing would suggest. As the git command wrapper as to make certain assumptions, the issue you see is expected.

However, in these cases one can pass the arguments explicitly, such as in this example:

repo.git.branch('-D', 'somebranch')

Please also note that the usage of repo.git is only advised as it's considered un-pythonic and bare-bone. A nicer way of achieving the branch creation and deletion presented here is the following:

foo = repo.create_head('foo')
assert foo.is_valid()
repo.delete_head(foo)
assert not foo.is_valid()

@Byron Byron closed this as completed Jan 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants