Skip to content

log does not work when used with --pretty=%P #710

@Shreeasish

Description

@Shreeasish

I tried to recreate git log --pretty=%P -n 1 <commit-id> in GitPython and there were some issues

I tried using this
REPO.git.log('--pretty=%P -n 1 202bfa07e1fbaf7d210468a2ca6c7f4352fc2b25')
Which sends it into a loop

This
REPO.git.log(' --pretty=%P -n 1 202bfa07e1fbaf7d210468a2ca6c7f4352fc2b25')
gives me this error:

GitCommandError                           Traceback (most recent call last)
<ipython-input-20-082da8bbf0c1> in <module>()
      1 #%%
----> 2 print(REPO.git.log(' --pretty=%P -n 1 202bfa07e1fbaf7d210468a2ca6c7f4352fc2b25'))
      3 # for each_line in REPO.git("log --pretty=%P -n 1 202bfa07e1fbaf7d210468a2ca6c7f4352fc2b25").split("\n"):
      4 #     print(each_line)
      5 

~/anaconda3/envs/gitwork/lib/python3.6/site-packages/git/cmd.py in <lambda>(*args, **kwargs)
    423         if name[0] == '_':
    424             return LazyMixin.__getattr__(self, name)
--> 425         return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
    426 
    427     def set_persistent_git_options(self, **kwargs):

~/anaconda3/envs/gitwork/lib/python3.6/site-packages/git/cmd.py in _call_process(self, method, *args, **kwargs)
    875         call.extend(args)
    876 
--> 877         return self.execute(call, **exec_kwargs)
    878 
    879     def _parse_object_header(self, header_line):

~/anaconda3/envs/gitwork/lib/python3.6/site-packages/git/cmd.py in execute(self, command, istream, with_extended_output, with_exceptions, as_process, output_stream, stdout_as_string, kill_after_timeout, with_stdout, universal_newlines, shell, **subprocess_kwargs)
    686 
    687         if with_exceptions and status != 0:
--> 688             raise GitCommandError(command, status, stderr_value, stdout_value)
    689 
    690         if isinstance(stdout_value, bytes) and stdout_as_string:  # could also be output_stream

GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git log  --pretty=%P -n 1 202bfa07e1fbaf7d210468a2ca6c7f4352fc2b25
  stderr: 'fatal: ambiguous argument ' --pretty=%P -n 1 202bfa07e1fbaf7d210468a2ca6c7f4352fc2b25': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]''

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions