Skip to content

Commit d3a7282

Browse files
author
Cory Johns
committed
[#5330] Ensure wait() is called on git processes
1 parent 5869c5c commit d3a7282

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

git/cmd.py

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def __del__(self):
8080
# try to kill it
8181
try:
8282
os.kill(self.proc.pid, 2) # interrupt signal
83+
self.proc.wait() # ensure process goes away
8384
except AttributeError:
8485
# try windows
8586
# for some reason, providing None for stdout/stderr still prints something. This is why

git/objects/commit.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Actor,
99
Iterable,
1010
Stats,
11+
finalize_process
1112
)
1213
from git.diff import Diffable
1314
from tree import Tree
@@ -251,6 +252,8 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream):
251252
assert len(hexsha) == 40, "Invalid line: %s" % hexsha
252253
yield Commit(repo, hex_to_bin(hexsha))
253254
# END for each line in stream
255+
if has_attr(proc_or_stream, 'wait'):
256+
finalize_process(proc_or_stream)
254257

255258

256259
@classmethod

git/remote.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
TagReference
2525
)
2626

27-
from git.util import join_path
27+
from git.util import (
28+
join_path,
29+
finalize_process
30+
)
2831
from gitdb.util import join
2932

3033
import re
@@ -58,18 +61,6 @@ def digest_process_messages(fh, progress):
5861
# END while file is not done reading
5962
return dropped_lines
6063

61-
def finalize_process(proc):
62-
"""Wait for the process (clone, fetch, pull or push) and handle its errors accordingly"""
63-
try:
64-
proc.wait()
65-
except GitCommandError,e:
66-
# if a push has rejected items, the command has non-zero return status
67-
# a return status of 128 indicates a connection error - reraise the previous one
68-
if proc.poll() == 128:
69-
raise
70-
pass
71-
# END exception handling
72-
7364
def add_progress(kwargs, git, progress):
7465
"""Add the --progress flag to the given kwargs dict if supported by the
7566
git command. If the actual progress in the given progress instance is not

git/repo/base.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
from git.exc import InvalidGitRepositoryError, NoSuchPathError
88
from git.cmd import Git
9-
from git.util import Actor
9+
from git.util import (
10+
Actor,
11+
finalize_process
12+
)
1013
from git.refs import *
1114
from git.index import IndexFile
1215
from git.objects import *
1316
from git.config import GitConfigParser
1417
from git.remote import (
1518
Remote,
1619
digest_process_messages,
17-
finalize_process,
1820
add_progress
1921
)
2022

@@ -541,6 +543,7 @@ def untracked_files(self):
541543
untracked_files.append(untracked_info.replace("#\t", "").rstrip())
542544
# END for each utracked info line
543545
# END for each line
546+
finalize_process(proc)
544547
return untracked_files
545548

546549
@property

git/util.py

+12
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ def get_user_id():
121121
# END get username from login
122122
return "%s@%s" % (username, platform.node())
123123

124+
def finalize_process(proc):
125+
"""Wait for the process (clone, fetch, pull or push) and handle its errors accordingly"""
126+
try:
127+
proc.wait()
128+
except GitCommandError,e:
129+
# if a push has rejected items, the command has non-zero return status
130+
# a return status of 128 indicates a connection error - reraise the previous one
131+
if proc.poll() == 128:
132+
raise
133+
pass
134+
# END exception handling
135+
124136
#} END utilities
125137

126138
#{ Classes

0 commit comments

Comments
 (0)