def test_diff_non_ascii(self): if sys.platform == 'win32': # Skip this test on Windows until we fix Unicode support return fp = 'new' new_fp_contents = '’◕‿◕’©Ä☺’ಠ_ಠ’\n' utils_lib.write_file(fp, contents=new_fp_contents) self.curr_b.track_file(fp) patch = self.curr_b.diff_file(fp) self.assertEqual(1, patch.line_stats[1]) self.assertEqual(0, patch.line_stats[2]) self.assertEqual(1, len(patch.hunks)) hunk = list(patch.hunks)[0] self.assertEqual(1, len(hunk.lines)) self.assertEqual('+', hunk.lines[0].origin) self.assertEqual(new_fp_contents, hunk.lines[0].content) utils_lib.append_to_file(fp, contents='new line') patch = self.curr_b.diff_file(fp) self.assertEqual(2, patch.line_stats[1]) self.assertEqual(0, patch.line_stats[2]) self.assertEqual(1, len(patch.hunks)) hunk = list(patch.hunks)[0] self.assertEqual(3, len(hunk.lines)) self.assertEqual('+', hunk.lines[0].origin) self.assertEqual(new_fp_contents, hunk.lines[0].content) self.assertEqual('+', hunk.lines[1].origin) self.assertEqual('new line', hunk.lines[1].content)
def test_diff_non_ascii(self): fp = 'new' new_fp_contents = '’◕‿◕’©Ä☺’ಠ_ಠ’\n' utils_lib.write_file(fp, contents=new_fp_contents) self.curr_b.track_file(fp) patch = self.curr_b.diff_file(fp) self.assertEqual(1, patch.line_stats[1]) self.assertEqual(0, patch.line_stats[2]) self.assertEqual(1, len(patch.hunks)) hunk = list(patch.hunks)[0] self.assertEqual(1, len(hunk.lines)) self.assertEqual('+', hunk.lines[0].origin) self.assertEqual(new_fp_contents, hunk.lines[0].content) utils_lib.append_to_file(fp, contents='new line') patch = self.curr_b.diff_file(fp) self.assertEqual(2, patch.line_stats[1]) self.assertEqual(0, patch.line_stats[2]) self.assertEqual(1, len(patch.hunks)) hunk = list(patch.hunks)[0] self.assertEqual(3, len(hunk.lines)) self.assertEqual('+', hunk.lines[0].origin) self.assertEqual(new_fp_contents, hunk.lines[0].content) self.assertEqual('+', hunk.lines[1].origin) self.assertEqual('new line', hunk.lines[1].content)
def test_conflicts_multiple_uncommitted_changes(self): gl.branch(c='tmp', divergent_point='HEAD~2') gl.switch('tmp') utils.append_to_file(self.MASTER_FILE, contents='conflict') gl.commit(m='will conflict 0') utils.append_to_file(self.MASTER_FILE, contents='conflict') gl.commit(m='will conflict 1') utils.write_file(self.MASTER_FILE, contents='uncommitted') self.assertRaisesRegexp(ErrorReturnCode, 'conflicts', gl.fuse, 'master') gl.resolve(self.MASTER_FILE) self.assertRaisesRegexp(ErrorReturnCode, 'conflicts', gl.commit, m='ci 0 in tmp') gl.resolve(self.MASTER_FILE) self.assertRaisesRegexp(ErrorReturnCode, 'failed to apply', gl.commit, m='ci 1 in tmp') self.__assert_history( self.__build('master') + self.__build('tmp', range(2))) self.assertTrue('Stashed' in utils.read_file(self.MASTER_FILE))
def test_diff_new_fp(self): fp = 'new' new_fp_contents = 'new fp contents\n' utils_lib.write_file(fp, contents=new_fp_contents) self.curr_b.track_file(fp) patch = self.curr_b.diff_file(fp) self.assertEqual(1, patch.line_stats[1]) self.assertEqual(0, patch.line_stats[2]) self.assertEqual(1, len(patch.hunks)) hunk = list(patch.hunks)[0] self.assertEqual(1, len(hunk.lines)) self.assertEqual('+', hunk.lines[0].origin) self.assertEqual(new_fp_contents, hunk.lines[0].content) # Now let's add some change to the file and check that diff notices it utils_lib.append_to_file(fp, contents='new line') patch = self.curr_b.diff_file(fp) self.assertEqual(2, patch.line_stats[1]) self.assertEqual(0, patch.line_stats[2]) self.assertEqual(1, len(patch.hunks)) hunk = list(patch.hunks)[0] self.assertEqual(3, len(hunk.lines)) self.assertEqual('+', hunk.lines[0].origin) self.assertEqual(new_fp_contents, hunk.lines[0].content) self.assertEqual('+', hunk.lines[1].origin) self.assertEqual('new line', hunk.lines[1].content)
def test_uncommitted_tracked_changes_that_conflict_append(self): gl.branch(c='tmp', divergent_point='HEAD~1') gl.switch('tmp') utils.append_to_file(self.MASTER_FILE, contents='uncommitted') self.assertRaisesRegexp(ErrorReturnCode, 'failed to apply', gl.merge, 'master') contents = utils.read_file(self.MASTER_FILE) self.assertTrue('uncommitted' in contents) self.assertTrue('contents 2' in contents)
def test_uncommitted_tracked_changes_that_conflict_append(self): gl.branch(c='tmp', divergent_point='HEAD~1') gl.switch('tmp') utils.append_to_file(self.MASTER_FILE, contents='uncommitted') self.assertRaisesRegexp( ErrorReturnCode, 'failed to apply', gl.merge, 'master') contents = utils.read_file(self.MASTER_FILE) self.assertTrue('uncommitted' in contents) self.assertTrue('contents 2' in contents)
def create_commits(branch_name, fp): self.commits[branch_name] = [] utils.append_to_file(fp, contents='contents {0}\n'.format(0)) out = utils.stdout(gl.commit(m='ci 0 in {0}'.format(branch_name), inc=fp)) self.commits[branch_name].append( re.search(r'Commit Id: (.*)', out, re.UNICODE).group(1)) for i in range(1, self.COMMITS_NUMBER): utils.append_to_file(fp, contents='contents {0}\n'.format(i)) out = utils.stdout(gl.commit(m='ci {0} in {1}'.format(i, branch_name))) self.commits[branch_name].append( re.search(r'Commit Id: (.*)', out, re.UNICODE).group(1))
def test_diff_append(self): utils_lib.append_to_file(TRACKED_FP, contents='new contents') patch = self.curr_b.diff_file(TRACKED_FP) self.assertEqual(1, patch.line_stats[1]) self.assertEqual(0, patch.line_stats[2]) self.assertEqual(1, len(patch.hunks)) hunk = list(patch.hunks)[0] self.assertEqual(3, len(hunk.lines)) self.assertEqual(' ', hunk.lines[0].origin) self.assertEqual(TRACKED_FP_CONTENTS_2, hunk.lines[0].content) self.assertEqual('+', hunk.lines[1].origin) self.assertEqual('new contents', hunk.lines[1].content)
def test_conflicts_multiple(self): gl.branch(c='tmp', divergent_point='HEAD~2') gl.switch('tmp') utils.append_to_file(self.MASTER_FILE, contents='conflict') gl.commit(m='will conflict 0') utils.append_to_file(self.MASTER_FILE, contents='conflict') gl.commit(m='will conflict 1') self.assertRaisesRegexp(ErrorReturnCode, 'conflicts', gl.fuse, 'master') gl.resolve(self.MASTER_FILE) self.assertRaisesRegexp( ErrorReturnCode, 'conflicts', gl.commit, m='ci 0 in tmp') gl.resolve(self.MASTER_FILE) gl.commit(m='ci 1 in tmp') # this one should finalize the fuse self.__assert_history( self.__build('master') + self.__build('tmp', range(2)))
def test_conflicts_multiple_uncommitted_changes(self): gl.branch(c='tmp', divergent_point='HEAD~2') gl.switch('tmp') utils.append_to_file(self.MASTER_FILE, contents='conflict') gl.commit(m='will conflict 0') utils.append_to_file(self.MASTER_FILE, contents='conflict') gl.commit(m='will conflict 1') utils.write_file(self.MASTER_FILE, contents='uncommitted') self.assertRaisesRegexp(ErrorReturnCode, 'conflicts', gl.fuse, 'master') gl.resolve(self.MASTER_FILE) self.assertRaisesRegexp( ErrorReturnCode, 'conflicts', gl.commit, m='ci 0 in tmp') gl.resolve(self.MASTER_FILE) self.assertRaisesRegexp( ErrorReturnCode, 'failed to apply', gl.commit, m='ci 1 in tmp') self.__assert_history( self.__build('master') + self.__build('tmp', range(2))) self.assertTrue('Stashed' in utils.read_file(self.MASTER_FILE))
def test_status_ignore_tracked(self): """Assert that ignoring a tracked file has no effect.""" utils_lib.append_to_file('.gitignore', contents='\n' + TRACKED_FP + '\n') st = self.curr_b.status_file(TRACKED_FP) self.__assert_type(TRACKED_FP, core.GL_STATUS_TRACKED, st.type)
def test_status_ignore_untracked(self): """Assert that ignoring a untracked file makes it ignored.""" utils_lib.append_to_file('.gitignore', contents='\n' + UNTRACKED_FP + '\n') st = self.curr_b.status_file(UNTRACKED_FP) self.__assert_type(UNTRACKED_FP, core.GL_STATUS_IGNORED, st.type)