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

Skip to content

Commit 9bcfe17

Browse files
authored
Merge pull request #844 from pre-commit/pre_push_ancestor_identification
fix pushing to new branch not identifying all commits
2 parents c0b1f2f + 3181b46 commit 9bcfe17

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

pre_commit/resources/hook-tmpl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,15 @@ def _pre_push(stdin):
123123
elif remote_sha != Z40 and _rev_exists(remote_sha):
124124
opts = ('--origin', local_sha, '--source', remote_sha)
125125
else:
126-
# First ancestor not found in remote
127-
first_ancestor = subprocess.check_output((
128-
'git', 'rev-list', '--max-count=1', '--topo-order',
129-
'--reverse', local_sha, '--not', '--remotes={}'.format(remote),
126+
# ancestors not found in remote
127+
ancestors = subprocess.check_output((
128+
'git', 'rev-list', local_sha, '--topo-order', '--reverse',
129+
'--not', '--remotes={}'.format(remote),
130130
)).decode().strip()
131-
if not first_ancestor:
131+
if not ancestors:
132132
continue
133133
else:
134+
first_ancestor = ancestors.splitlines()[0]
134135
cmd = ('git', 'rev-list', '--max-parents=0', local_sha)
135136
roots = set(subprocess.check_output(cmd).decode().splitlines())
136137
if first_ancestor in roots:

tests/commands/install_uninstall_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,13 @@ def test_pre_push_integration_failing(tempdir_factory, store):
527527
install(Runner(path, C.CONFIG_FILE), store, hook_type='pre-push')
528528
# commit succeeds because pre-commit is only installed for pre-push
529529
assert _get_commit_output(tempdir_factory)[0] == 0
530+
assert _get_commit_output(tempdir_factory, touch_file='zzz')[0] == 0
530531

531532
retc, output = _get_push_output(tempdir_factory)
532533
assert retc == 1
533534
assert 'Failing hook' in output
534535
assert 'Failed' in output
536+
assert 'foo zzz' in output # both filenames should be printed
535537
assert 'hookid: failing_hook' in output
536538

537539

0 commit comments

Comments
 (0)