def _test(self): commit_id = repo.make_commit(changed='O') repo.write_files(changed='X', staged='staged', untracked='untracked') GIT.add('staged') expected = [' M changed', 'A staged', '?? untracked'] self.assertEqual(_status(), expected) return commit_id
def test_offset_and_safe(self): repo.make_commit('1') repo.make_commit('2') GIT.push('-u', 'origin', 'master') stripe('--count=2 --offset=3') actual = functions.branches('-r') expected = [ 'origin/_gitz_stripe_3', 'origin/_gitz_stripe_4', 'origin/master', 'upstream/master', ] self.assertEqual(actual, expected) stripe('--count=2 --safe') actual = functions.branches('-r') expected = [ 'origin/_gitz_stripe_3', 'origin/_gitz_stripe_4', 'origin/_gitz_stripe_5', 'origin/_gitz_stripe_6', 'origin/master', 'upstream/master', ] self.assertEqual(actual, expected)
def TODO_test_example(self): # Why does this fail? Debugging gives nonsensical results! # GIT.permute('__cba_', '-v') GIT.permute('edcf', '-v') actual = GIT.log('--oneline')[:4] expected = [] self.assertEqual(actual, expected)
def test(self): repo.make_seven_commits(self) GIT.permute('01234', '-v', '-s', 'TEST') actual = GIT.log('--oneline') expected = ['bbd9e40 TEST', '043df1f 2', 'a03c0f8 1', 'c0d1dbb 0'] self.assertEqual(actual, expected)
def test_empty_squash(self): repo.make_seven_commits(self) GIT.permute('01234', '-v', '-s') actual = GIT.log('--oneline') expected = ['059f1ee 3', '043df1f 2', 'a03c0f8 1', 'c0d1dbb 0'] self.assertEqual(actual, expected)
def test_rename(self): GIT.mv('0', '1') actual = GIT.infer('-v') expected = [ '[master e147e06] Rename 0 -> 1', ' 1 file changed, 0 insertions(+), 0 deletions(-)', ' rename 0 => 1 (100%)', ] self.assertEqual(actual, expected)
def test_use_head_unstaged(self): repo.make_commit('1') repo.write_file('1', '2') GIT.new('one', '-vu') with open('1') as fp: self.assertEqual(fp.read(), '2') actual = GIT.log('--oneline', 'origin/one') expected = ['a03c0f8 1', 'c0d1dbb 0'] self.assertEqual(actual, expected)
def test_default(self): repo.make_seven_commits(self) GIT.reset('--soft', 'HEAD~') GIT.adjust('-v') actual = GIT.log('--oneline')[:4] expected = ['84e8ee1 6', '8a4a4e2 5', 'a7c7e8f 4', '9ab30c5 3'] self.assertEqual(expected, actual) self.assertEqual(['6', '7'], _files_in_commit())
def test_all_tracked(self): repo.make_seven_commits(self) repo.write_file('6', 'DELTA') GIT.adjust('-a', '-v') actual = GIT.log('--oneline')[:4] expected = ['067af20 7', 'e1e931a 6', '8a4a4e2 5', 'a7c7e8f 4'] self.assertEqual(expected, actual) self.assertEqual(['6', '7'], _files_in_commit())
def test_message(self): repo.make_seven_commits(self) GIT.adjust('HEAD~3', '--commit=HEAD~', '-m', '4 and 6', '-v') actual = GIT.log('--oneline')[:4] expected = ['d43e4a8 7', 'e38207c 5', 'ac920db 4 and 6', '9ab30c5 3'] self.assertEqual(expected, actual) self.assertEqual(['7'], _files_in_commit()) self.assertEqual(['5'], _files_in_commit('HEAD~')) self.assertEqual(['4', '6'], _files_in_commit('HEAD~~'))
def test_commit(self): repo.make_seven_commits(self) GIT.adjust('HEAD~3', '--commit=HEAD~', '-v') actual = GIT.log('--oneline')[:4] expected = ['18f631a 7', '6c901a6 5', '9375333 4', '9ab30c5 3'] self.assertEqual(expected, actual) self.assertEqual(['7'], _files_in_commit()) self.assertEqual(['5'], _files_in_commit('HEAD~')) self.assertEqual(['4', '6'], _files_in_commit('HEAD~~'))
def test_simple(self): repo.make_seven_commits(self) GIT.reset('--soft', 'HEAD~') GIT.adjust('HEAD~', '-v') actual = GIT.log('--oneline')[:4] expected = ['0e103e7 6', '207bd13 5', 'a7c7e8f 4', '9ab30c5 3'] self.assertEqual(expected, actual) self.assertEqual(['6'], _files_in_commit()) self.assertEqual(['5', '7'], _files_in_commit('HEAD~'))
def test_add(self): with open('1', 'w') as fp: fp.write('1\n') GIT.add('1') actual = GIT.infer() expected = [ '[master 0ae685e] Add 1', ' 1 file changed, 1 insertion(+)', ' create mode 100644 1', ] self.assertEqual(actual, expected)
def test_new(self): GIT.new('one', '-v') repo.make_commit('1') GIT.push() actual = GIT.log('--oneline', 'origin/one') expected = ['a03c0f8 1', 'c0d1dbb 0'] self.assertEqual(actual, expected) GIT.new('two', '-v') repo.make_commit('2') GIT.push() actual = GIT.log('--oneline', 'origin/two') expected = ['aff4d90 2', 'c0d1dbb 0'] self.assertEqual(actual, expected)
def test_change(self): with self.assertRaises(Exception): GIT.infer() with open('0', 'w') as fp: fp.write('1\n') with self.assertRaises(Exception): GIT.infer() actual = GIT.infer('-av') expected = [ '[master 72515ed] Modify 0', ' 1 file changed, 1 insertion(+), 1 deletion(-)', ] self.assertEqual(actual, expected)
def test_all(self): # See #170 indent_commands = ((' ' if c else '') + c for c in COMMANDS) indent_commands = '\n'.join(indent_commands) home_page = config.HOME_PAGE executable_directory = str(config.EXECUTABLE_DIRECTORY) library_directory = str(config.LIBRARY_DIRECTORY) version = config.__version__ python_version = platform.python_version() platform_name = platform.platform() commands = list(_commands()) indent_commands = indent_commands def filter_results(lines): results = [] prev = '' py = ' Python' xd = 'Executable directory:' for line in lines: if not (line.startswith(py) or prev.startswith(xd)): results.append(line) prev = line return results results = RESULTS.format(**locals()) expected = filter_results(results.splitlines()) actual = filter_results(GIT.gitz('-v')) self.assertEqual(expected, actual)
def test_executable_directory(self): result = { GIT.gitz(d, '-v')[0] for d in ('e', 'exec', 'executable_directory') } self.assertEqual(len(result), 1) result = next(iter(result)) self.assertTrue((Path(result) / 'git-gitz').exists())
def _setup(self): repo.make_commit('1') repo.make_commit('2') repo.make_commit('3') repo.make_commit('4') GIT.push('-u', 'origin', 'master') stripe('--count=3') actual = functions.branches('-r') expected = [ 'origin/_gitz_stripe_0', 'origin/_gitz_stripe_1', 'origin/_gitz_stripe_2', 'origin/master', 'upstream/master', ] self.assertEqual(actual, expected)
def test_range_setting(self): repo.make_commit('1') two = repo.make_commit('2') repo.make_commit('3') four = repo.make_commit('4') repo.make_commit('5') GIT.push('-u', 'origin', 'master') stripe(two, four) actual = functions.branches('-r') expected = [ 'origin/_gitz_stripe_0', 'origin/_gitz_stripe_1', 'origin/master', 'upstream/master', ] self.assertEqual(actual, expected)
def test_git(self): with self.main('-c', 'git:') as execute: repo.write_files('a', 'b', 'c') observer, = execute.observed observer(None) patch.wait() files = GIT.diff_tree('--no-commit-id', '--name-only', '-r', 'HEAD') assert set(files) == set('abc')
def test_remove(self): repo.make_commit('1') os.remove('0') actual = GIT.infer('-av') expected = [ '[master 1d56dde] Remove 0', ' 1 file changed, 1 deletion(-)', ' delete mode 100644 0', ] self.assertEqual(actual, expected)
def test_test_files(self): self._test_files() actual = GIT.log('--oneline') expected = [ '2a2c087 3', '4fbc0b7 6', 'adf954d 4', 'a03c0f8 1', 'c0d1dbb 0', ] self.assertEqual(actual, expected)
def test_change(self): repo.make_commit('1') repo.make_commit('2') actual = GIT.when() expected = [ r'0.* ago.*c0d1dbb.*0.*', r'1.* ago.*a03c0f8.*1.*', r'2.* ago.*043df1f.*2.*', ] for a, e in zip(actual, expected): self.assertRegex(a, e) self.assertEqual(len(actual), len(expected))
def test_branches(self): self.assertEqual('44dac6b', repo.make_commit('one.txt')) current = functions.branch_name() GIT.checkout('-b', 'foo') self.assertEqual(repo.make_commit('two.txt'), '393ad1c') GIT.checkout(current) GIT.checkout('-b', 'bar') self.assertEqual(repo.make_commit('three.txt'), 'b6aee43') actual = GIT.for_each('-', 'git', 'log', '--oneline') self.assertEqual(actual, _BRANCHES.split('\n'))
def test_simple(self): repo.make_commit('1', '2') GIT.push() with open('3', 'w') as fp: fp.write('3\n') GIT.add('3') with open('4', 'w') as fp: fp.write('4\n') with open('0', 'w') as fp: fp.write('100\n') os.remove('1') actual = GIT.st() expected = [ '\x1b[32mmaster\x1b[m...\x1b[31morigin/master\x1b[m', ' \x1b[31mM\x1b[m 0 | 2 \x1b[32m+\x1b[m\x1b[31m-\x1b[m', ' \x1b[31mD\x1b[m 1 | 1 \x1b[31m-\x1b[m', '\x1b[32mA\x1b[m 3 | 1 \x1b[32m+\x1b[m', '\x1b[31m??\x1b[m 4 ', ] self.assertEqual(actual, expected)
def test_multiple(self): repo.make_commit('1') repo.make_commit('2') GIT.mv('0', '3') os.remove('1') with open('4', 'w') as fp: fp.write('4\n') with open('2', 'w') as fp: fp.write('6\n') GIT.add('2', '4') actual = GIT.infer('-v') expected = [ '[master e80d1bc] Several changes', ' 3 files changed, 2 insertions(+), 1 deletion(-)', ' rename 0 => 3 (100%)', ' create mode 100644 4', ] self.assertEqual(actual, expected)
def test_clone(self): self.assertEqual('44dac6b', repo.make_commit('one.txt')) self.assertEqual('393ad1c', repo.make_commit('two.txt')) GIT.checkout('-b', 'working') repo.add_remotes(['foo', 'bar']) expected = ['bar', 'foo', 'origin', 'upstream'] self.assertEqual(sorted(GIT.remote()), expected) functions.fetch('foo') functions.fetch('bar') actual = functions.branches('-r') expected = [ 'bar/working', 'foo/working', 'origin/master', 'upstream/master', ] self.assertEqual(actual, expected) self.assertEqual('efc4ce6', repo.make_commit('three.txt')) GIT.push('foo', 'HEAD:working') self.assertEqual(functions.commit_id('bar/working'), '393ad1c') self.assertEqual(functions.commit_id('foo/working'), 'efc4ce6')
def test_delete(self): GIT.new('one') repo.make_commit('1') GIT.push() GIT.new('two') repo.make_commit('2') GIT.push() actual = functions.branches('-r') expected = [ 'origin/master', 'origin/one', 'origin/two', 'upstream/master', ] self.assertEqual(actual, expected) GIT.delete('one', 'two', '-v') actual = functions.branches('-r') expected = ['origin/master', 'upstream/master'] self.assertEqual(actual, expected)
def test_all(self): commit_id = self._test() status = _status() GIT.save('-a', '-v') self.assertEqual(commit_id, functions.commit_id()) self.assertEqual(status, _status()) GIT.reset('--hard', 'HEAD~') repo.make_seven_commits(self) GIT.save('pop', '-v') self.assertEqual(status, _status())
def _get_files(self, *args): GIT.checkout('-b', 'A') repo.make_commit('1') repo.make_commit('2') three = repo.make_commit('3') repo.make_commit('4') five = repo.make_commit('5') repo.make_commit('6') GIT.checkout('master') GIT.multi_pick('-v', three, five, *args) files = sorted(i for i in os.listdir() if not i.startswith('.')) self.assertEqual(files, ['0', '3', '5'])