changeset 7363:6af08d44daa8

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.
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 08 Aug 2018 02:23:11 +0200
parents a19f1649c8d4
children 61bd3efe4a6c
files kallithea/lib/hooks.py kallithea/tests/other/test_vcs_operations.py
diffstat 2 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/hooks.py	Wed Aug 08 02:23:11 2018 +0200
+++ b/kallithea/lib/hooks.py	Wed Aug 08 02:23:11 2018 +0200
@@ -447,11 +447,11 @@
                     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()
 
--- a/kallithea/tests/other/test_vcs_operations.py	Wed Aug 08 02:23:11 2018 +0200
+++ b/kallithea/tests/other/test_vcs_operations.py	Wed Aug 08 02:23:11 2018 +0200
@@ -290,20 +290,20 @@
         # 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:
         # <UserLog('id:new_git_XXX:started_following_repo')>
         # <UserLog('id:new_git_XXX:user_created_repo')>
         # <UserLog('id:new_git_XXX:pull')>
-        # - but no push logging
+        # <UserLog('id:new_git_XXX:push:aed9d4c1732a1927da3be42c47eb9afdc200d427,d38b083a07af10a9f44193486959a96a23db78da,4841ff9a2b385bec995f4679ef649adb3f437622')>
         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()