Skip to content
Prev Previous commit
Next Next commit
Prevent CMD windows being shown when starting git in a subprocess.
This fixes a UI problem with using GitPython from a GUI python probgram.
Each repo that is opened creates a git cat-file processs and that provess will create
a console window with out this change.
  • Loading branch information
barry-scott committed Jul 29, 2016
commit 0d9390866f9ce42870d3116094cd49e0019a970a
15 changes: 14 additions & 1 deletion git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ def execute(self, command,
# end handle

try:
if sys.platform == 'win32':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally for these kinds of assignment, I believe it's easier to read by starting out like this:

creationflags = None
if sys.platform == 'win32':
    creationflags = CREATE_NO_WINDOW

CREATE_NO_WINDOW = 0x08000000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATE_NO_WINDOW is used twice, is there a reason it is not a constant on module or class level ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intended to provide a obvious patch. You usually change my process control patches so I left that for you to decide on where you wished to define CREATE_NO_WINDOW.

creationflags = CREATE_NO_WINDOW
else:
creationflags = None

proc = Popen(command,
env=env,
cwd=cwd,
Expand All @@ -619,6 +625,7 @@ def execute(self, command,
shell=self.USE_SHELL,
close_fds=(os.name == 'posix'), # unsupported on windows
universal_newlines=universal_newlines,
creationflags=creationflags,
**subprocess_kwargs
)
except cmd_not_found_exception as err:
Expand All @@ -629,7 +636,13 @@ def execute(self, command,

def _kill_process(pid):
""" Callback method to kill a process. """
p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE)
if sys.platform == 'win32':
CREATE_NO_WINDOW = 0x08000000
creationflags = CREATE_NO_WINDOW
else:
creationflags = None

p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE, creationflags)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid that using creationflags as positional argument doesn't actually end up in the correct spot. Also I thought that positional arguments after keyword args are not allowed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This concern is reflected in actual breakage as well: https://travis-ci.org/gitpython-developers/GitPython/jobs/148304657#L318

child_pids = []
for line in p.stdout:
if len(line.split()) > 0:
Expand Down