# HG changeset patch # User Mads Kiilerich # Date 2018-08-08 02:23:11 # Node ID 6af08d44daa805bc6d4629ebec236cbef35efd2d # Parent a19f1649c8d44ffe7d1d9d8ed8ac8f25bd5ae439 git: fix push to empty repo (Issue 323) Git would fail to log revisions when the list of heads to exclude included an empty string (in place of the pushed ref). To avoid that, skip the skipped revision instead of making it an empty string. `git log --not` works fine without providing any revisions to "not". Verify in test_push_new_repo_git that it actually logged the push. diff --git a/kallithea/lib/hooks.py b/kallithea/lib/hooks.py --- a/kallithea/lib/hooks.py +++ b/kallithea/lib/hooks.py @@ -447,11 +447,11 @@ def handle_git_post_receive(repo_path, g cmd = ['for-each-ref', '--format=%(refname)', 'refs/heads/*'] stdout, stderr = scm_repo.run_git_command(cmd) ref = push_ref['ref'] - heads = [head if head != ref else '' for head in stdout.splitlines()] + heads = [head for head in stdout.splitlines() if head != ref] # now list the git revs while excluding from the list cmd = ['log', push_ref['new_rev'], '--reverse', '--pretty=format:%H'] cmd.append('--not') - cmd.extend(heads) + cmd.extend(heads) # empty list is ok stdout, stderr = scm_repo.run_git_command(cmd) git_revs += stdout.splitlines() diff --git a/kallithea/tests/other/test_vcs_operations.py b/kallithea/tests/other/test_vcs_operations.py --- a/kallithea/tests/other/test_vcs_operations.py +++ b/kallithea/tests/other/test_vcs_operations.py @@ -290,20 +290,20 @@ class TestVCSOperations(TestController): # refs/heads/master we are pushing, but the `git log` in the push hook # should still list the 3 commits. stdout, stderr = _add_files_and_push(webserver, 'git', local_clone_dir, clone_url=clone_url) - # FIXME: the push kind of failed with something like: - # remote: fatal: ambiguous argument '': unknown revision or path not in the working tree. - assert 'remote: fatal' in stderr + _check_proper_git_push(stdout, stderr) # Verify that we got the right events in UserLog. Expect something like: # # # - # - but no push logging + # uls = list(UserLog.query().order_by(UserLog.user_log_id)) - assert len(uls) == 3 + assert len(uls) == 4 assert uls[0].action == 'started_following_repo' assert uls[1].action == 'user_created_repo' assert uls[2].action == 'pull' + assert uls[3].action.startswith(u'push:') + assert uls[3].action.count(',') == 2 # expect 3 commits def test_push_new_file_hg(self, webserver, testfork): dest_dir = _get_tmp_dir()