Changeset - 6af08d44daa8
[Not reviewed]
default
0 2 0
Mads Kiilerich - 7 years ago 2018-08-08 02:23:11
mads@kiilerich.com
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.
2 files changed with 7 insertions and 7 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/hooks.py
Show inline comments
 
@@ -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()
 

	
kallithea/tests/other/test_vcs_operations.py
Show inline comments
 
@@ -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:
 
        # <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()
0 comments (0 inline, 0 general)