Implement merge-files only using @bukzor's method.

This commit is contained in:
Anthony Sottile 2014-04-14 22:50:16 -07:00
parent 94d626691f
commit 5810ee4315
5 changed files with 115 additions and 23 deletions

View file

@ -283,26 +283,6 @@ def test_has_unmerged_paths(output, expected):
assert commands._has_unmerged_paths(mock_runner) is expected
@pytest.yield_fixture
def in_merge_conflict(repo_with_passing_hook):
local['git']['add', C.CONFIG_FILE]()
local['git']['commit', '-m' 'add hooks file']()
local['git']['clone', '.', 'foo']()
with local.cwd('foo'):
local['git']['checkout', 'origin/master', '-b', 'foo']()
with open('conflict_file', 'w') as conflict_file:
conflict_file.write('herp\nderp\n')
local['git']['add', 'conflict_file']()
local['git']['commit', '-m', 'conflict_file']()
local['git']['checkout', 'origin/master', '-b', 'bar']()
with open('conflict_file', 'w') as conflict_file:
conflict_file.write('harp\nddrp\n')
local['git']['add', 'conflict_file']()
local['git']['commit', '-m', 'conflict_file']()
local['git']['merge', 'foo'](retcode=None)
yield os.path.join(repo_with_passing_hook, 'foo')
def test_merge_conflict(in_merge_conflict):
ret, printed = _do_run(in_merge_conflict, _get_opts())
assert ret == 1

View file

@ -1,5 +1,7 @@
from __future__ import absolute_import
import os
import os.path
import pytest
import time
import yaml
@ -126,3 +128,29 @@ def repo_with_passing_hook(config_for_script_hooks_repo, empty_git_dir):
def repo_with_failing_hook(failing_hook_repo, empty_git_dir):
_make_repo_from_configs(_make_config(failing_hook_repo, 'failing_hook', ''))
yield empty_git_dir
@pytest.yield_fixture
def in_merge_conflict(repo_with_passing_hook):
local['git']['add', C.CONFIG_FILE]()
local['git']['commit', '-m' 'add hooks file']()
local['git']['clone', '.', 'foo']()
with local.cwd('foo'):
local['git']['checkout', 'origin/master', '-b', 'foo']()
with open('conflict_file', 'w') as conflict_file:
conflict_file.write('herp\nderp\n')
local['git']['add', 'conflict_file']()
with open('foo_only_file', 'w') as foo_only_file:
foo_only_file.write('foo')
local['git']['add', 'foo_only_file']()
local['git']['commit', '-m', 'conflict_file']()
local['git']['checkout', 'origin/master', '-b', 'bar']()
with open('conflict_file', 'w') as conflict_file:
conflict_file.write('harp\nddrp\n')
local['git']['add', 'conflict_file']()
with open('bar_only_file', 'w') as bar_only_file:
bar_only_file.write('bar')
local['git']['add', 'bar_only_file']()
local['git']['commit', '-m', 'conflict_file']()
local['git']['merge', 'foo'](retcode=None)
yield os.path.join(repo_with_passing_hook, 'foo')

View file

@ -14,6 +14,14 @@ def test_get_root(empty_git_dir):
assert git.get_root() == empty_git_dir
def test_is_in_merge_conflict(empty_git_dir):
assert git.is_in_merge_conflict() is False
def test_is_not_in_merge_conflict(in_merge_conflict):
assert git.is_in_merge_conflict() is True
@pytest.fixture
def get_files_matching_func():
def get_filenames():
@ -57,3 +65,48 @@ def test_does_not_include_deleted_fileS(get_files_matching_func):
def test_exclude_removes_files(get_files_matching_func):
ret = get_files_matching_func('', '\\.py$')
assert ret == set(['hooks.yaml'])
def resolve_conflict():
with open('conflict_file', 'w') as conflicted_file:
conflicted_file.write('herp\nderp\n')
local['git']['add', 'conflict_file']()
def test_get_conflicted_files(in_merge_conflict):
resolve_conflict()
with open('other_file', 'w') as other_file:
other_file.write('oh hai')
local['git']['add', 'other_file']()
ret = set(git.get_conflicted_files())
assert ret == set(('conflict_file', 'other_file'))
def test_get_conflicted_files_unstaged_files(in_merge_conflict):
# If they for whatever reason did pre-commit run --no-stash during a
# conflict
resolve_conflict()
# Make unstaged file.
with open('bar_only_file', 'w') as bar_only_file:
bar_only_file.write('new contents!\n')
ret = set(git.get_conflicted_files())
assert ret == set(('conflict_file',))
MERGE_MSG = "Merge branch 'foo' into bar\n\nConflicts:\n\tconflict_file\n"
OTHER_MERGE_MSG = MERGE_MSG + '\tother_conflict_file\n'
@pytest.mark.parametrize(
('input', 'expected_output'),
(
(MERGE_MSG, ['conflict_file']),
(OTHER_MERGE_MSG, ['conflict_file', 'other_conflict_file']),
),
)
def test_parse_merge_msg_for_conflicts(input, expected_output):
ret = git.parse_merge_msg_for_conflicts(input)
assert ret == expected_output