示例#1
0
    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)
示例#2
0
    def test_update(self):
        first = repo.make_one_commit('file.txt', ORIGINAL, 'original')
        self.assertEqual(first, '28da9aa')

        second = repo.make_one_commit('file.txt', DELTA3, 'master!')
        self.assertEqual(second, 'd1b2fc8')

        GIT.push('--set-upstream', 'upstream', 'master')
        GIT.reset('--hard', 'HEAD~')
        GIT.push('--set-upstream', 'origin', 'master')

        # No conflicts
        GIT.new('one')
        repo.make_commit('one')
        GIT.push()

        # Resolvable conflict
        GIT.new('two')
        repo.make_one_commit('file.txt', DELTA1, 'two')
        GIT.push()

        # Unresolvable conflict
        # TODO: this didn't work
        GIT.new('three')
        repo.make_one_commit('file.txt', DELTA2, 'three')
        GIT.push()

        # Local differs from origin
        GIT.new('four')
        repo.make_one_commit('file.txt', 'four', 'four')

        GIT.checkout('master')
        GIT.update('-v')

        lines = [first + ' original', 'c0d1dbb 0']

        def test(branch, *items):
            actual = GIT.log('--oneline', branch)
            expected = list(items) + lines
            self.assertEqual(expected, actual)

        test('master')
        test('origin/master')

        lines.insert(0, second + ' master!')

        test('upstream/master')

        test('one', '2b7979a one')
        test('origin/one', '2b7979a one')

        test('two', '5478a38 two')
        test('origin/two', '5478a38 two')

        test('three', '6158500 three')
        test('origin/three', '6158500 three')

        test('four', '62584d2 four')
        test('origin/four', '62584d2 four')
示例#3
0
文件: git_new_test.py 项目: rec/gitz
 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)
示例#4
0
 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'))
示例#5
0
 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)
示例#6
0
文件: git_when_test.py 项目: rec/gitz
 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))
示例#7
0
    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'])
示例#8
0
文件: git_new_test.py 项目: rec/gitz
    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)
示例#9
0
文件: git_save_test.py 项目: rec/gitz
 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
示例#10
0
    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)
示例#11
0
文件: git_st_test.py 项目: rec/gitz
    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)
示例#12
0
文件: git_rot_test.py 项目: rec/gitz
    def test_change(self):
        GIT.checkout('-b', 'A')
        repo.make_commit('1')

        GIT.checkout('-b', 'B')
        repo.make_commit('2')

        GIT.checkout('-b', 'C')
        repo.make_commit('3')
        self.assertEqual(functions.branch_name(), 'C')

        GIT.rot('0', '-v')
        self.assertEqual(functions.branch_name(), 'C')

        GIT.rot('-v')
        self.assertEqual(functions.branch_name(), 'master')

        GIT.rot('-v')
        self.assertEqual(functions.branch_name(), 'A')

        GIT.rot('2', '-v')
        self.assertEqual(functions.branch_name(), 'C')

        GIT.rot('-1', '-v')
        self.assertEqual(functions.branch_name(), 'B')

        GIT.rot('-', '-v')
        self.assertEqual(functions.branch_name(), 'A')

        GIT.rot('-2', '-v')
        self.assertEqual(functions.branch_name(), 'C')
示例#13
0
    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')
示例#14
0
    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)
示例#15
0
    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)
示例#16
0
    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)
示例#17
0
 def test_simple(self):
     repo.make_commit('1')
     GIT.new('one')
     GIT.rename('two', '-v')
     expected = {'origin': ['master', 'two'], 'upstream': ['master']}
     self.assertEqual(functions.remote_branches(), expected)
示例#18
0
    def test_repo(self):
        self.assertEqual('44dac6b', repo.make_commit('one.txt'))
        with self.assertRaises(Exception):
            repo.make_commit('one.txt')

        self.assertEqual('393ad1c', repo.make_commit('two.txt'))