MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / _pre_push_ns

Function _pre_push_ns

pre_commit/commands/hook_impl.py:120–174  ·  view source on GitHub ↗
(
        color: bool,
        args: Sequence[str],
        stdin: bytes,
)

Source from the content-addressed store, hash-verified

118
119
120def _pre_push_ns(
121 color: bool,
122 args: Sequence[str],
123 stdin: bytes,
124) -> argparse.Namespace | None:
125 remote_name = args[0]
126 remote_url = args[1]
127
128 for line in stdin.decode().splitlines():
129 parts = line.rsplit(maxsplit=3)
130 local_branch, local_sha, remote_branch, remote_sha = parts
131 if local_sha == Z40:
132 continue
133 elif remote_sha != Z40 and _rev_exists(remote_sha):
134 return _ns(
135 'pre-push', color,
136 from_ref=remote_sha, to_ref=local_sha,
137 remote_branch=remote_branch,
138 local_branch=local_branch,
139 remote_name=remote_name, remote_url=remote_url,
140 )
141 else:
142 # ancestors not found in remote
143 ancestors = subprocess.check_output((
144 'git', 'rev-list', local_sha, '--topo-order', '--reverse',
145 '--not', f'--remotes={remote_name}',
146 )).decode().strip()
147 if not ancestors:
148 continue
149 else:
150 first_ancestor = ancestors.splitlines()[0]
151 cmd = ('git', 'rev-list', '--max-parents=0', local_sha)
152 roots = set(subprocess.check_output(cmd).decode().splitlines())
153 if first_ancestor in roots:
154 # pushing the whole tree including root commit
155 return _ns(
156 'pre-push', color,
157 all_files=True,
158 remote_name=remote_name, remote_url=remote_url,
159 remote_branch=remote_branch,
160 local_branch=local_branch,
161 )
162 else:
163 rev_cmd = ('git', 'rev-parse', f'{first_ancestor}^')
164 source = subprocess.check_output(rev_cmd).decode().strip()
165 return _ns(
166 'pre-push', color,
167 from_ref=source, to_ref=local_sha,
168 remote_name=remote_name, remote_url=remote_url,
169 remote_branch=remote_branch,
170 local_branch=local_branch,
171 )
172
173 # nothing to push
174 return None
175
176
177_EXPECTED_ARG_LENGTH_BY_HOOK = {

Callers 1

_run_nsFunction · 0.85

Calls 2

_rev_existsFunction · 0.85
_nsFunction · 0.85

Tested by

no test coverage detected