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_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 test_remove(self): gl.branch(c=self.BRANCH_1) gl.switch(self.BRANCH_1) self.assertRaises(ErrorReturnCode, gl.branch, d=self.BRANCH_1, _in='y') gl.branch(c=self.BRANCH_2) gl.switch(self.BRANCH_2) gl.branch(d=self.BRANCH_1, _in='n') gl.branch(d=self.BRANCH_1, _in='y') if self.BRANCH_1 in utils.stdout(gl.branch()): self.fail()
def test_remove(self): gl.branch(c=self.BRANCH_1) gl.switch(self.BRANCH_1) self.assertRaises(ErrorReturnCode, gl.branch, d=self.BRANCH_1, _in='y') gl.branch(c=self.BRANCH_2) gl.switch(self.BRANCH_2) gl.branch(d=self.BRANCH_1, _in='n') gl.branch(d=self.BRANCH_1, _in='y') if self.BRANCH_1 in utils.stdout(gl.branch(_tty_out=False)): self.fail()
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 setUp(self): super(TestOp, self).setUp() self.commits = {} 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)) gl.branch(c=self.OTHER) create_commits('master', self.MASTER_FILE) gl.switch(self.OTHER) create_commits(self.OTHER, self.OTHER_FILE) gl.switch('master')
def test_branch_switch_performance(self): MAX_TOLERANCE = 100 gl.commit('f1', m='commit') t = time.time() gl.branch(c='develop') gl.switch('develop') gl_t = time.time() - t # go back to previous state gl.switch('master') # do the same for git t = time.time() git.branch('gitdev') git.stash.save('--all') git.checkout('gitdev') git_t = time.time() - t self.assertTrue(gl_t < git_t * MAX_TOLERANCE, msg='gl_t {0}, git_t {1}'.format(gl_t, git_t))
def test_branch_switch_performance(self): MAX_TOLERANCE = 100 gl.commit(o='f1', m='commit') t = time.time() gl.branch(c='develop') gl.switch('develop') gl_t = time.time() - t # go back to previous state gl.switch('master') # do the same for git t = time.time() git.branch('gitdev') git.stash.save('--all') git.checkout('gitdev') git_t = time.time() - t self.assertTrue( gl_t < git_t*MAX_TOLERANCE, msg='gl_t {0}, git_t {1}'.format(gl_t, git_t))
def test_create(self): gl.branch(c=self.BRANCH_1) self.assertRaises(ErrorReturnCode, gl.branch, c=self.BRANCH_1) self.assertRaises(ErrorReturnCode, gl.branch, c='evil*named*branch') if self.BRANCH_1 not in utils.stdout(gl.branch(_tty_out=False)): self.fail()
def test_ff_ip_head(self): gl.branch(c='tmp', divergent_point='HEAD~2') gl.switch('tmp') gl.fuse('master', insertion_point='HEAD') self.__assert_history(self.__build('master'))
def test_basic_functionality(self): utils.write_file('file1', 'Contents of file1') # Track gl.track('file1') self.assertRaises(ErrorReturnCode, gl.track, 'file1') self.assertRaises(ErrorReturnCode, gl.track, 'non-existent') # Untrack gl.untrack('file1') self.assertRaises(ErrorReturnCode, gl.untrack, 'file1') self.assertRaises(ErrorReturnCode, gl.untrack, 'non-existent') # Commit gl.track('file1') gl.commit(m='file1 commit') self.assertRaises(ErrorReturnCode, gl.commit, m='nothing to commit') # History if 'file1 commit' not in utils.stdout(gl.history()): self.fail('Commit didn\'t appear in history') # Branch # Make some changes to file1 and branch out utils.write_file('file1', 'New contents of file1') gl.branch(c='branch1') gl.switch('branch1') if 'New' in utils.read_file('file1'): self.fail('Branch not independent!') # Switch back to master branch, check that contents are the same as before. gl.switch('master') if 'New' not in utils.read_file('file1'): self.fail('Branch not independent!') out = utils.stdout(gl.branch()) if '* master' not in out: self.fail('Branch status output wrong: {0}'.format(out)) if 'branch1' not in out: self.fail('Branch status output wrong: {0}'.format(out)) gl.branch(c='branch2') gl.branch(c='branch-conflict1') gl.branch(c='branch-conflict2') gl.commit(m='New contents commit') # Fuse gl.switch('branch1') self.assertRaises(ErrorReturnCode, gl.fuse) # no upstream set try: gl.fuse('master') except ErrorReturnCode as e: self.fail(utils.stderr(e)) out = utils.stdout(gl.history()) if 'file1 commit' not in out: self.fail(out) # Merge gl.switch('branch2') self.assertRaises(ErrorReturnCode, gl.merge) # no upstream set gl.merge('master') out = utils.stdout(gl.history()) if 'file1 commit' not in out: self.fail(out) # Conflicting fuse gl.switch('branch-conflict1') utils.write_file('file1', 'Conflicting changes to file1') gl.commit(m='changes in branch-conflict1') err = utils.stderr(gl.fuse('master', _ok_code=[1])) if 'conflict' not in err: self.fail(err) out = utils.stdout(gl.status()) if 'file1 (with conflicts)' not in out: self.fail(out) # Try aborting gl.fuse('--abort') out = utils.stdout(gl.status()) if 'file1' in out: self.fail(out) # Ok, now let's fix the conflicts err = utils.stderr(gl.fuse('master', _ok_code=[1])) if 'conflict' not in err: self.fail(err) out = utils.stdout(gl.status()) if 'file1 (with conflicts)' not in out: self.fail(out) utils.write_file('file1', 'Fixed conflicts!') self.assertRaises(ErrorReturnCode, gl.commit, m='resolve not called') self.assertRaises(ErrorReturnCode, gl.resolve, 'non-existent') gl.resolve('file1') gl.commit(m='fixed conflicts')
def test_basic_functionality(self): utils.write_file('file1', 'Contents of file1') # Track gl.track('file1') self.assertRaises(ErrorReturnCode, gl.track, 'file1') self.assertRaises(ErrorReturnCode, gl.track, 'non-existent') # Untrack gl.untrack('file1') self.assertRaises(ErrorReturnCode, gl.untrack, 'file1') self.assertRaises(ErrorReturnCode, gl.untrack, 'non-existent') # Commit gl.track('file1') gl.commit(m='file1 commit') self.assertRaises(ErrorReturnCode, gl.commit, m='nothing to commit') # History if 'file1 commit' not in utils.stdout(gl.history(_tty_out=False)): self.fail('Commit didn\'t appear in history') # Branch # Make some changes to file1 and branch out utils.write_file('file1', 'New contents of file1') gl.branch(c='branch1') gl.switch('branch1') if 'New' in utils.read_file('file1'): self.fail('Branch not independent!') # Switch back to master branch, check that contents are the same as before. gl.switch('master') if 'New' not in utils.read_file('file1'): self.fail('Branch not independent!') out = utils.stdout(gl.branch(_tty_out=False)) if '* master' not in out: self.fail('Branch status output wrong: {0}'.format(out)) if 'branch1' not in out: self.fail('Branch status output wrong: {0}'.format(out)) gl.branch(c='branch2') gl.branch(c='branch-conflict1') gl.branch(c='branch-conflict2') gl.commit(m='New contents commit') # Fuse gl.switch('branch1') self.assertRaises(ErrorReturnCode, gl.fuse) # no upstream set try: gl.fuse('master') except ErrorReturnCode as e: self.fail(utils.stderr(e)) out = utils.stdout(gl.history(_tty_out=False)) if 'file1 commit' not in out: self.fail(out) # Merge gl.switch('branch2') self.assertRaises(ErrorReturnCode, gl.merge) # no upstream set gl.merge('master') out = utils.stdout(gl.history(_tty_out=False)) if 'file1 commit' not in out: self.fail(out) # Conflicting fuse gl.switch('branch-conflict1') utils.write_file('file1', 'Conflicting changes to file1') gl.commit(m='changes in branch-conflict1') err = utils.stderr(gl.fuse('master', _tty_out=False, _ok_code=[1])) if 'conflict' not in err: self.fail(err) out = utils.stdout(gl.status(_tty_out=False)) if 'file1 (with conflicts)' not in out: self.fail(out) # Try aborting gl.fuse('--abort') out = utils.stdout(gl.status(_tty_out=False)) if 'file1' in out: self.fail(out) # Ok, now let's fix the conflicts err = utils.stderr(gl.fuse('master', _tty_out=False, _ok_code=[1])) if 'conflict' not in err: self.fail(err) out = utils.stdout(gl.status(_tty_out=False)) if 'file1 (with conflicts)' not in out: self.fail(out) utils.write_file('file1', 'Fixed conflicts!') self.assertRaises(ErrorReturnCode, gl.commit, m='resolve not called') self.assertRaises(ErrorReturnCode, gl.resolve, 'non-existent') gl.resolve('file1') gl.commit(m='fixed conflicts')
def test_list(self): gl.branch(c=self.BRANCH_1) gl.branch(c=self.BRANCH_2) branch_out = utils.stdout(gl.branch()) self.assertTrue( branch_out.find(self.BRANCH_1) < branch_out.find(self.BRANCH_2))
def test_create(self): gl.branch(c=self.BRANCH_1) self.assertRaises(ErrorReturnCode, gl.branch, c=self.BRANCH_1) self.assertRaises(ErrorReturnCode, gl.branch, c='evil*named*branch') if self.BRANCH_1 not in utils.stdout(gl.branch()): self.fail()