Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7bb878b

Browse files
committed
Use 'cwd' parameter of subprocess functions
1 parent 8298af0 commit 7bb878b

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

mypy/git.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,33 @@ def have_git() -> bool:
2121
return False
2222

2323

24-
def run_in_dir(dir, command) -> bytes:
25-
"""Convenience function: Run a command in a directory."""
26-
return subprocess.check_output("cd " + pipes.quote(dir) + "; " + command,
27-
shell=True)
28-
29-
3024
def get_submodules(dir: str):
3125
"""Return a list of all git top-level submodules in a given directory."""
3226
# It would be nicer to do
3327
# "git submodule foreach 'echo MODULE $name $path $sha1 $toplevel'"
3428
# but that wouldn't work on Windows.
35-
output = run_in_dir(dir, "git submodule status")
29+
output = subprocess.check_output(["git", "submodule", "status"], cwd=dir)
3630
for line in output.splitlines():
3731
status = line[0]
38-
sha5, name, *_ = line[1:].split(b" ")
39-
yield (status, sha5, name.decode(sys.getfilesystemencoding()))
32+
revision, name, *_ = line[1:].split(b" ")
33+
yield (status, revision, name.decode(sys.getfilesystemencoding()))
4034

4135

4236
def git_revision(dir: str) -> bytes:
4337
"""Get the SHA-1 of the HEAD of a git repository."""
44-
return run_in_dir(dir, "git rev-parse HEAD").strip()
38+
return subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=dir).strip()
4539

4640

4741
def is_dirty(dir: str) -> bool:
4842
"""Check whether a git repository has uncommitted changes."""
49-
return run_in_dir(dir, "git status -uno --porcelain").strip() != b""
43+
output = subprocess.check_output(["git", "status", "-uno", "--porcelain"], cwd=dir)
44+
return output.strip() != b""
5045

5146

5247
def has_extra_files(dir: str) -> bool:
5348
"""Check whether a git repository has untracked files."""
54-
return run_in_dir(dir, "git clean --dry-run -d").strip() != b""
49+
output = subprocess.check_output(["git", "clean", "--dry-run", "-d"], cwd=dir)
50+
return output.strip() != b""
5551

5652

5753
def warn_no_git_executable() -> None:
@@ -62,11 +58,17 @@ def warn_no_git_executable() -> None:
6258
def warn_dirty(dir) -> None:
6359
print("Warning: git module '{}' has uncommitted changes.".format(dir),
6460
file=sys.stderr)
61+
print("Got to the directory", file=sys.stderr)
62+
print(" {}".format(dir), file=sys.stderr)
63+
print("and commit or reset your changes", file=sys.stderr)
6564

6665

6766
def warn_extra_files(dir) -> None:
6867
print("Warning: git module '{}' has untracked files.".format(dir),
6968
file=sys.stderr)
69+
print("Got to the directory", file=sys.stderr)
70+
print(" {}".format(dir), file=sys.stderr)
71+
print("and add & commit your new files.", file=sys.stderr)
7072

7173

7274
def error_submodule_not_initialized(name: str, dir: str) -> None:
@@ -81,6 +83,8 @@ def error_submodule_not_updated(name: str, dir: str) -> None:
8183
print("Please run:", file=sys.stderr)
8284
print(" cd {}".format(pipes.quote(dir)), file=sys.stderr)
8385
print(" git submodule update {}".format(name), file=sys.stderr)
86+
print("(If you got this message because you updated {}".format(name), file=sys.stderr)
87+
print(" then run \"git add {}\" to silence this check)")
8488

8589

8690
def verify_git_integrity_or_abort(datadir: str) -> None:

mypy/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def process_options(args: List[str]) -> Tuple[str, str, str, Options]:
123123
args = args[2:]
124124
elif args[0] == '-f' or args[0] == '--dirty-stubs':
125125
options.dirty_stubs = True
126-
args = args[2:]
126+
args = args[1:]
127127
elif args[0] == '-m' and args[1:]:
128128
options.build_flags.append(build.MODULE)
129129
return None, args[1], None, options

0 commit comments

Comments
 (0)