def testCommit(self): newfile = os.path.join(self.repodir, 'newfile') touch(newfile) run_cmd(['hg', 'add', 'newfile'], cwd=self.repodir) rev = commit(self.repodir, user='******', msg='gooooood') info = getRevInfo(self.repodir, rev) self.assertEquals(info['msg'], 'gooooood')
def testShareExtraFiles(self): shareBase = os.path.join(self.tmpdir, 'share') backup = os.path.join(self.tmpdir, 'backup') # Clone the original repo mercurial(self.repodir, self.wc, shareBase=shareBase) clone(self.repodir, backup) # Make the working repo have a new file. We need it to have an earlier # timestamp (yesterday) to trigger the odd behavior in hg newfile = os.path.join(self.wc, 'newfile') touch(newfile, timestamp=yesterday_timestamp()) run_cmd(['hg', 'add', 'newfile'], cwd=self.wc) run_cmd(['hg', 'commit', '-m', '"add newfile"'], cwd=self.wc) # Reset the share base to remove the 'add newfile' commit. We # overwrite repodir with the backup that doesn't have the commit, # then clone the repodir to a throwaway dir to create the new # shareBase. Now self.wc still points to shareBase, but the # changeset that self.wc was on is lost. shutil.rmtree(self.repodir) shutil.rmtree(shareBase) clone(backup, self.repodir) throwaway = os.path.join(self.tmpdir, 'throwaway') mercurial(self.repodir, throwaway, shareBase=shareBase) # Try and update our working copy mercurial(self.repodir, self.wc, shareBase=shareBase) self.assertFalse(os.path.exists(os.path.join(self.wc, 'newfile')))
def testGitShare(self): shareBase = os.path.join(self.tmpdir, 'git-repos') rev = git.git(self.repodir, self.wc, shareBase=shareBase) shareDir = os.path.join(shareBase, git.get_repo_name(self.repodir)) self.assertEquals(rev, self.revisions[-1]) # We should see all the revisions revs = getRevisions( self.wc, branches=['origin/master', 'origin/branch2']) shared_revs = getRevisions( shareDir, branches=['origin/master', 'origin/branch2']) self.assertEquals(revs, shared_revs) self.assertEquals(revs, self.revisions) # Update to a different rev rev = git.git(self.repodir, self.wc, revision=self.revisions[0], shareBase=shareBase) self.assertEquals(rev, self.revisions[0]) self.assertFalse(os.path.exists(os.path.join(self.wc, 'newfile'))) # Add a commit to the original repo newfile = os.path.join(self.repodir, 'newfile') touch(newfile) run_cmd(['git', 'add', 'newfile'], cwd=self.repodir) run_cmd(['git', 'commit', '-q', '-m', 'add newfile'], cwd=self.repodir) new_rev = getRevisions(self.repodir)[-1] # Update to the new rev rev = git.git( self.repodir, self.wc, revision=new_rev, shareBase=shareBase) self.assertEquals(rev, new_rev) self.assertTrue(os.path.exists(os.path.join(self.wc, 'newfile')))
def testPushWithForce(self): clone(self.repodir, self.wc, revision=self.revisions[0], clone_by_rev=True) newfile = os.path.join(self.wc, 'newfile') touch(newfile) run_cmd(['hg', 'add', 'newfile'], cwd=self.wc) run_cmd(['hg', 'commit', '-m', '"re-add newfile"'], cwd=self.wc) push(self.repodir, self.wc, push_new_branches=False, force=True)
def c(repo, attempt, remote, local): newfile_remote = os.path.join(remote, 'newfile') newfile_local = os.path.join(local, 'newfile') touch(newfile_remote) run_cmd(['hg', 'add', 'newfile'], cwd=remote) run_cmd(['hg', 'commit', '-m', '"add newfile"'], cwd=remote) touch(newfile_local) run_cmd(['hg', 'add', 'newfile'], cwd=local) run_cmd(['hg', 'commit', '-m', '"re-add newfile"'], cwd=local)
def testPushForceFail(self): clone(self.repodir, self.wc, revision=self.revisions[0], clone_by_rev=True) newfile = os.path.join(self.wc, 'newfile') touch(newfile) run_cmd(['hg', 'add', 'newfile'], cwd=self.wc) run_cmd(['hg', 'commit', '-m', '"add newfile"'], cwd=self.wc) self.assertRaises(Exception, push, self.repodir, self.wc, push_new_branches=False, force=False)
def testGitRev(self): rev = git.git(self.repodir, self.wc) self.assertEquals(rev, self.revisions[-1]) # Update to a different rev rev = git.git(self.repodir, self.wc, revision=self.revisions[1]) self.assertEquals(rev, self.revisions[1]) # Make a new commit in repodir newfile = os.path.join(self.repodir, 'newfile') touch(newfile) run_cmd(['git', 'add', 'newfile'], cwd=self.repodir) run_cmd(['git', 'commit', '-q', '-m', 'add newfile'], cwd=self.repodir) new_rev = getRevisions(self.repodir)[-1] rev = git.git(self.repodir, self.wc, revision=new_rev) self.assertEquals(new_rev, rev)
def testGitMirrors(self): # Create a bad mirror and a good mirror mirror1 = os.path.join(self.tmpdir, 'mirror1') mirror2 = os.path.join(self.tmpdir, 'mirror2') git.git(self.repodir, mirror2, update_dest=False) rev = git.git(self.repodir, self.wc, mirrors=[mirror1, mirror2]) self.assertEquals(rev, self.revisions[-1]) # Add a commit to the mirror newfile = os.path.join(mirror2, 'newfile') touch(newfile) run_cmd(['git', 'add', 'newfile'], cwd=mirror2) run_cmd(['git', 'commit', '-q', '-m', 'add newfile'], cwd=mirror2) new_rev = getRevisions(mirror2)[-1] # Now clone using the mirror. We should get the new commit that's in # the mirror rev = git.git(self.repodir, self.wc, mirrors=[mirror1, mirror2]) self.assertEquals(rev, new_rev)
def testFetchAll(self): # Clone just the main branch git.clone(self.repodir, self.wc, update_dest=False) # Now pull in branch2 git.fetch(self.repodir, self.wc, refname='branch2') # Change the original repo newfile = os.path.join(self.repodir, 'newfile') touch(newfile) run_cmd(['git', 'add', 'newfile'], cwd=self.repodir) run_cmd(['git', 'commit', '-q', '-m', 'add newfile'], cwd=self.repodir) # Now pull in everything from master branch git.fetch(self.repodir, self.wc, refname='master') for branch in 'master', 'branch2': self.assertEquals(getRevisions(self.wc, branches=['origin/%s' % branch]), getRevisions(self.repodir, branches=[branch])) # Make sure we actually changed something self.assertNotEqual(getRevisions( self.repodir, branches=['master', 'branch2']), self.revisions)
def testShareExtraFilesReset(self): shareBase = os.path.join(self.tmpdir, 'share') # Clone the original repo mercurial(self.repodir, self.wc, shareBase=shareBase) # Reset the repo run_cmd( ['%s/init_hgrepo.sh' % os.path.dirname(__file__), self.repodir]) # Make the working repo have a new file. We need it to have an earlier # timestamp (yesterday) to trigger the odd behavior in hg newfile = os.path.join(self.wc, 'newfile') touch(newfile, timestamp=yesterday_timestamp()) run_cmd(['hg', 'add', 'newfile'], cwd=self.wc) run_cmd(['hg', 'commit', '-m', '"add newfile"'], cwd=self.wc) # Try and update our working copy mercurial(self.repodir, self.wc, shareBase=shareBase) self.assertFalse(os.path.exists(os.path.join(self.wc, 'newfile')))
def testGitShare(self): shareBase = os.path.join(self.tmpdir, 'git-repos') rev = git.git(self.repodir, self.wc, shareBase=shareBase) shareDir = os.path.join(shareBase, git.get_repo_name(self.repodir)) self.assertEquals(rev, self.revisions[-1]) # We should see all the revisions revs = getRevisions(self.wc, branches=['origin/master', 'origin/branch2']) shared_revs = getRevisions( shareDir, branches=['origin/master', 'origin/branch2']) self.assertEquals(revs, shared_revs) self.assertEquals(revs, self.revisions) # Update to a different rev rev = git.git(self.repodir, self.wc, revision=self.revisions[0], shareBase=shareBase) self.assertEquals(rev, self.revisions[0]) self.assertFalse(os.path.exists(os.path.join(self.wc, 'newfile'))) # Add a commit to the original repo newfile = os.path.join(self.repodir, 'newfile') touch(newfile) run_cmd(['git', 'add', 'newfile'], cwd=self.repodir) run_cmd(['git', 'commit', '-q', '-m', 'add newfile'], cwd=self.repodir) new_rev = getRevisions(self.repodir)[-1] # Update to the new rev rev = git.git(self.repodir, self.wc, revision=new_rev, shareBase=shareBase) self.assertEquals(rev, new_rev) self.assertTrue(os.path.exists(os.path.join(self.wc, 'newfile')))
def testFetchAll(self): # Clone just the main branch git.clone(self.repodir, self.wc, update_dest=False) # Now pull in branch2 git.fetch(self.repodir, self.wc, refname='branch2') # Change the original repo newfile = os.path.join(self.repodir, 'newfile') touch(newfile) run_cmd(['git', 'add', 'newfile'], cwd=self.repodir) run_cmd(['git', 'commit', '-q', '-m', 'add newfile'], cwd=self.repodir) # Now pull in everything from master branch git.fetch(self.repodir, self.wc, refname='master') for branch in 'master', 'branch2': self.assertEquals( getRevisions(self.wc, branches=['origin/%s' % branch]), getRevisions(self.repodir, branches=[branch])) # Make sure we actually changed something self.assertNotEqual( getRevisions(self.repodir, branches=['master', 'branch2']), self.revisions)