MCPcopy Create free account
hub / github.com/pytorch/executorch / run_git

Function run_git

scripts/pick_doc_commits.py:45–76  ·  view source on GitHub ↗

Runs a git command and returns its stdout as a list of lines. Prints the command and its output to debug_log() if verbosity is greater than 1. Args: command: The args to pass to `git`, without the leading `git` itself. Returns: A list of the non-empty lines printed

(command: List[str])

Source from the content-addressed store, hash-verified

43
44
45def run_git(command: List[str]) -> List[str]:
46 """Runs a git command and returns its stdout as a list of lines.
47
48 Prints the command and its output to debug_log() if verbosity is greater
49 than 1.
50
51 Args:
52 command: The args to pass to `git`, without the leading `git` itself.
53 Returns:
54 A list of the non-empty lines printed to stdout, without trailing
55 newlines.
56 Raises:
57 Exception: The command failed.
58 """
59 try:
60 if verbosity > 1: # Higher verbosity required
61 debug_log("Running command: 'git " + " ".join(command) + "'")
62 result = subprocess.run(["git", *command], capture_output=True, text=True)
63 if result.returncode != 0:
64 raise Exception(f"Error running command '{command}':\n{result.stderr}")
65 lines = result.stdout.split("\n")
66 # Remove empty and whitespace-only lines.
67 lines = [line.strip() for line in lines if line.strip()]
68 global verbose
69 if verbosity > 1:
70 debug_log("-----BEGIN GIT OUTPUT-----")
71 for line in lines:
72 debug_log(line)
73 debug_log("-----END GIT OUTPUT-----")
74 return lines
75 except Exception as e:
76 raise Exception(f"Error running command '{command}': {e}")
77
78
79class Commit:

Callers 3

__init__Method · 0.85
is_doc_only_commitFunction · 0.85
mainFunction · 0.85

Calls 3

debug_logFunction · 0.85
splitMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected