Skip to content

GitCommand errors are stringifying bytes in 3.1.15 #1220

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
jmcgill298 opened this issue Apr 21, 2021 · 1 comment · Fixed by #1222
Closed

GitCommand errors are stringifying bytes in 3.1.15 #1220

jmcgill298 opened this issue Apr 21, 2021 · 1 comment · Fixed by #1222

Comments

@jmcgill298
Copy link
Contributor

The 3.1.15 release changed at least how git.exc.GitCommandError Errors are being generated. I have tested with stderr, but am guessing the same would be true for stdout. Previously git.exc.GitCommandError.stderr was a string of the error with bytes decoded, now the error is a string with bytes stringified.

repo.git.rebase Error:

  • 3.1.14-stderr = "\n stderr: 'fatal: invalid upstream 'invalid_branch''"
  • 3.1.15-stderr = '\n stderr: \'b"fatal: invalid upstream \'invalid_branch\'"\''

remote.push Error:

  • 3.1.14-stderr = "\n stderr: 'error: src refspec invalid_branch does not match any\nerror: failed to push some refs to '[email protected]:project/repo.git''"
  • 3.1.15-stderr = '\n stderr: \'b"error: src refspec invalid_branch does not match any\\nerror: failed to push some refs to \'[email protected]:project/repo.git\'"\''

Steps to reproduce:

import git

exception = git.exc.CommandError(command="git rebase invalid_branch".split(), stderr=b"abc")
exception.stderr

Steps to reproduce from code

import git

path_to_repo = "my_project"
repo = git.Repo(path_to_repo)

local_branch = "invalid_branch"
remote_branch = local_branch

# Generate Error for Rebase
try:
    repo.git.rebase(refspec=f"{remote_branch})"
except Exception as err:
    print(err.stderr)

# Generate Error for Push
try:
    repo.remotes[0].push(f"{local_branch}:{remote_branch}")
except Exception as err:
    print(err.stderr)
@jmcgill298
Copy link
Contributor Author

This was introduced by 5232c89 in #1202

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

Successfully merging a pull request may close this issue.

2 participants