-
-
Notifications
You must be signed in to change notification settings - Fork 954
-
Hi,
I am using gitpython for a small helper tool to manage somewhat complicated submodule setups.
I want it to work alongside standard git, not agaionst or around it.
Hence I want users to see the output of the commands. as they know it from plain vanilla git
e.g. a "Everything up to date" after a push without changes.
From the docs I was not really able to figure out a consistent way to do it.
For commit, I was able to achieve it like this: print(toprepo.git.commit(a=pa.add, m=msg, with_stdout=True))
For push, the same does not work, because it ends up on stderr print(toprepo.git.push(pa.remote, with_stdout=True))
:
Logger produces this:
INFO:git.cmd:git push origin -> 0; stdout: '<OUTPUT_STREAM>'; stderr: 'Everything up-to-date'
When using the built in remote.push() and remote.pull() methosds I cannot find a way to retrieve the output at all, as with_stdout=False is hardcoded without a way to override it via kwargs.
Can you give guidance on how to cover my use-case?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 1 reply
-
Using repo.git.<command>
syntax essentially calls git
and captures stdout and stderr, returning both usually depending on the configuration.
When dealing with remotes there are facilities in place which capture stderr to make progress messages easier to use. Have a look at the p'progress' portion of the advanced usage docs for some details.
If the script is mostly for calling the git command, a shell script might be easier to work with than GitPython which has its own peculiarities when calling git.
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1
-
Yes we currently do have a shell script but due to some requirements we have decided to switch to python, so
I am essentially coming from this direction.
I appreciate the facilities GitPython provides, so using it was a deliberate choice.
Essentially I also want all the return containers for use in further processing, in the process I just want the user to see the direct output of the called git actions.
For the repo.git. commands I think I understand how to use stdout, but where does stderr end up?
and for the remot.push/pull I have read the section you suggested, but I stil no not quite get on how to just print what would've been printed by the git command (and still receive the FetchInfo objects that contain success info)
Beta Was this translation helpful? Give feedback.
All reactions
-
Stderr is always configured as pipe, so it would never show up in the parent terminal.
Line 825 in 33346b2
This is why it is always consumed in code and parsed on the fly, feeding into progress handlers.
Line 826 in 33346b2
Line 698 in 33346b2
These can also see the original line if the correct method is overridden.
Line 737 in 33346b2
Currently there is no way to not pipe stderr and display it to the enclosing terminal. You would rather have to launch the git command yourself.
Beta Was this translation helpful? Give feedback.