def testPushWithRevision(self): clone(self.repodir, self.wc, revision=self.revisions[-1], clone_by_rev=True) push(src=self.repodir, remote=self.wc, revision=self.revisions[-2]) self.assertEquals(getRevisions(self.wc), self.revisions[-2:])
def testPushForceFail(self): clone(self.repodir, self.wc, revision=self.revisions[0], clone_by_rev=True) run_cmd(['touch', 'newfile'], cwd=self.wc) 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 testApplyAndPushFail(self): clone(self.repodir, self.wc) def c(repo, attempt, remote): run_cmd(['hg', 'tag', '-f', 'TEST'], cwd=repo) run_cmd(['hg', 'tag', '-f', 'CONFLICTING_TAG'], cwd=remote) self.assertRaises(HgUtilError, apply_and_push, self.wc, self.repodir, lambda r, a: c(r, a, self.repodir), max_attempts=2)
def testCloneWithBundleMissingRevs(self): # First create the bundle bundle = os.path.join(self.tmpdir, "bundle") run_cmd(["hg", "bundle", "-a", bundle], cwd=self.repodir) # Create a commit open(os.path.join(self.repodir, "test.txt"), "w").write("hello!") run_cmd(["hg", "add", "test.txt"], cwd=self.repodir) run_cmd(["hg", "commit", "-m", "adding changeset"], cwd=self.repodir) # Wrap unbundle so we can tell if it got called orig_unbundle = unbundle try: called = [] def new_unbundle(*args, **kwargs): called.append(True) return orig_unbundle(*args, **kwargs) hg.unbundle = new_unbundle # Now clone it using the bundle clone(self.repodir, self.wc, bundles=[bundle]) self.assertEquals(getRevisions(self.repodir), getRevisions(self.wc)) self.assertEquals(called, [True]) finally: hg.unbundle = orig_unbundle
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 testCloneWithBundleMissingRevs(self): # First create the bundle bundle = os.path.join(self.tmpdir, 'bundle') run_cmd(['hg', 'bundle', '-a', bundle], cwd=self.repodir) # Create a commit open(os.path.join(self.repodir, 'test.txt'), 'w').write('hello!') run_cmd(['hg', 'add', 'test.txt'], cwd=self.repodir) run_cmd(['hg', 'commit', '-m', 'adding changeset'], cwd=self.repodir) # Wrap unbundle so we can tell if it got called orig_unbundle = unbundle try: called = [] def new_unbundle(*args, **kwargs): called.append(True) return orig_unbundle(*args, **kwargs) hg.unbundle = new_unbundle # Now clone it using the bundle clone(self.repodir, self.wc, bundles=[bundle]) self.assertEquals(getRevisions(self.repodir), getRevisions(self.wc)) self.assertEquals(called, [True]) finally: hg.unbundle = orig_unbundle
def testOutofSyncMirrorFailingMaster(self): # First create the mirror mirror = os.path.join(self.tmpdir, 'repo2') clone(self.repodir, mirror) shareBase = os.path.join(self.tmpdir, 'share') os.mkdir(shareBase) mercurial(self.repodir, self.wc, shareBase=shareBase, mirrors=[mirror]) # Create a bundle bundle = os.path.join(self.tmpdir, 'bundle') run_cmd(['hg', 'bundle', '-a', bundle], cwd=self.repodir) # Move our repodir out of the way so that pulling/cloning from it fails os.rename(self.repodir, self.repodir + "-bad") # Try and update to a non-existent revision using our mirror and # bundle, with the master failing. We should fail self.assertRaises(subprocess.CalledProcessError, mercurial, self.repodir, self.wc, shareBase=shareBase, mirrors=[mirror], bundles=[bundle], revision="1234567890")
def testApplyAndPush(self): clone(self.repodir, self.wc) def c(repo, attempt): run_cmd(['hg', 'tag', '-f', 'TEST'], cwd=repo) apply_and_push(self.wc, self.repodir, c) self.assertEquals(getRevisions(self.wc), getRevisions(self.repodir))
def testPushWithForce(self): clone(self.repodir, self.wc, revision=self.revisions[0], clone_by_rev=True) run_cmd(['touch', 'newfile'], cwd=self.wc) 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 testApplyAndPushWithNoChange(self): clone(self.repodir, self.wc) def c(r, a): pass self.assertRaises( HgUtilError, apply_and_push, self.wc, self.repodir, c)
def testCloneRevision(self): clone(self.repodir, self.wc, revision=self.revisions[0], update_dest=False, clone_by_rev=True) # We'll only get a subset of the revisions self.assertEquals(self.revisions[:1] + self.revisions[2:], getRevisions(self.wc))
def testCloneWithBundleMissingRevs(self): # First create the bundle bundle = os.path.join(self.tmpdir, 'bundle') run_cmd(['hg', 'bundle', '-a', bundle], cwd=self.repodir) # Create a commit open(os.path.join(self.repodir, 'test.txt'), 'w').write('hello!') run_cmd(['hg', 'add', 'test.txt'], cwd=self.repodir) run_cmd(['hg', 'commit', '-m', 'adding changeset'], cwd=self.repodir) # Wrap unbundle so we can tell if it got called orig_unbundle = unbundle try: called = [] def new_unbundle(*args, **kwargs): called.append(True) return orig_unbundle(*args, **kwargs) hg.unbundle = new_unbundle # Now clone it using the bundle clone(self.repodir, self.wc, bundles=[bundle]) self.assertEquals( getRevisions(self.repodir), getRevisions(self.wc)) self.assertEquals(called, [True]) finally: hg.unbundle = orig_unbundle
def testPurgeUntrackedFile(self): clone(self.repodir, self.wc) fileToPurge = os.path.join(self.wc, "fileToPurge") with file(fileToPurge, "a") as f: f.write("purgeme") purge(self.wc) self.assertFalse(os.path.exists(fileToPurge))
def testPurgeUntrackedFile(self): clone(self.repodir, self.wc) fileToPurge = os.path.join(self.wc, 'fileToPurge') with file(fileToPurge, 'a') as f: f.write('purgeme') purge(self.wc) self.assertFalse(os.path.exists(fileToPurge))
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 to trigger the odd behavior in hg, so use '-d yesterday' run_cmd(['touch', '-d', 'yesterday', 'newfile'], cwd=self.wc) 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 testCloneBranch(self): clone(self.repodir, self.wc, branch="branch2", update_dest=False, clone_by_rev=True) # On hg 1.6, we should only have a subset of the revisions if hg_ver() >= (1, 6, 0): self.assertEquals(self.revisions[1:], getRevisions(self.wc)) else: self.assertEquals(self.revisions, getRevisions(self.wc))
def testOutofSyncMirrorFailingMaster(self): # First create the mirror mirror = os.path.join(self.tmpdir, "repo2") clone(self.repodir, mirror) shareBase = os.path.join(self.tmpdir, "share") os.mkdir(shareBase) mercurial(self.repodir, self.wc, shareBase=shareBase, mirrors=[mirror]) # Create a bundle bundle = os.path.join(self.tmpdir, "bundle") run_cmd(["hg", "bundle", "-a", bundle], cwd=self.repodir) # Move our repodir out of the way so that pulling/cloning from it fails os.rename(self.repodir, self.repodir + "-bad") # Try and update to a non-existent revision using our mirror and # bundle, with the master failing. We should fail self.assertRaises( subprocess.CalledProcessError, mercurial, self.repodir, self.wc, shareBase=shareBase, mirrors=[mirror], bundles=[bundle], revision="1234567890", )
def testApplyAndPushWithNoChange(self): clone(self.repodir, self.wc) def c(r, a): pass self.assertRaises(HgUtilError, apply_and_push, self.wc, self.repodir, c)
def testPushWithBranch(self): clone(self.repodir, self.wc, revision=self.revisions[-1], clone_by_rev=True) push(src=self.repodir, remote=self.wc, branch='branch2') push(src=self.repodir, remote=self.wc, branch='default') self.assertEquals(getRevisions(self.wc), self.revisions)
def testPullDefault(self): clone(self.repodir, self.wc) run_cmd(["hg", "tag", "-f", "TAG1"], cwd=self.repodir) revisions = getRevisions(self.repodir) rev = pull(self.repodir, self.wc, revision="default") self.assertEquals(rev, revisions[0]) self.assertEquals(getRevisions(self.wc), revisions)
def testPullDefault(self): clone(self.repodir, self.wc) run_cmd(['hg', 'tag', '-f', 'TAG1'], cwd=self.repodir) revisions = getRevisions(self.repodir) rev = pull(self.repodir, self.wc, revision='default') self.assertEquals(rev, revisions[0]) self.assertEquals(getRevisions(self.wc), revisions)
def testApplyAndPush(self): clone(self.repodir, self.wc) def c(repo, attempt): run_cmd(["hg", "tag", "-f", "TEST"], cwd=repo) apply_and_push(self.wc, self.repodir, c) self.assertEquals(getRevisions(self.wc), getRevisions(self.repodir))
def testPurgeTrackedFile(self): clone(self.repodir, self.wc) fileToModify = os.path.join(self.wc, 'hello.txt') with open(fileToModify, 'w') as f: f.write('hello!') purge(self.wc) with open(fileToModify, 'r') as f: content = f.read() self.assertEqual(content, 'hello!')
def testCloneWithBadMirror(self): mirror = os.path.join(self.tmpdir, 'repo2') # Now clone from the mirror clone(self.repodir, self.wc, mirrors=[mirror]) # We still end up with a valid repo self.assertEquals(self.revisions, getRevisions(self.wc)) self.assertEquals(self.repodir, path(self.wc))
def testPurgeTrackedFile(self): clone(self.repodir, self.wc) fileToModify = os.path.join(self.wc, "hello.txt") with open(fileToModify, "w") as f: f.write("hello!") purge(self.wc) with open(fileToModify, "r") as f: content = f.read() self.assertEqual(content, "hello!")
def testApplyAndPushRebaseFails(self): clone(self.repodir, self.wc) def c(repo, attempt, remote): run_cmd(['hg', 'tag', '-f', 'TEST'], cwd=repo) if attempt in (1,2): run_cmd(['hg', 'tag', '-f', 'CONFLICTING_TAG'], cwd=remote) apply_and_push(self.wc, self.repodir, lambda r, a: c(r, a, self.repodir), max_attempts=3) self.assertEquals(getRevisions(self.wc), getRevisions(self.repodir))
def testPull(self): # Clone just the first rev clone(self.repodir, self.wc, revision=self.revisions[-1], update_dest=False, clone_by_rev=True) self.assertEquals(getRevisions(self.wc), self.revisions[-1:]) # Now pull in new changes rev = pull(self.repodir, self.wc, update_dest=False) self.assertEquals(rev, None) self.assertEquals(getRevisions(self.wc), self.revisions)
def testPurgeVeryLongPath(self): clone(self.repodir, self.wc) # now create a very long path name longPath = self.wc for new_dir in xrange(1, 64): longPath = os.path.join(longPath, str(new_dir)) os.makedirs(longPath) self.assertTrue(os.path.isdir(longPath)) purge(self.wc) self.assertFalse(os.path.isdir(longPath))
def testApplyAndPushWithRebase(self): clone(self.repodir, self.wc) def c(repo, attempt, remote): run_cmd(['hg', 'tag', '-f', 'TEST'], cwd=repo) if attempt == 1: run_cmd(['hg', 'rm', 'hello.txt'], cwd=remote) run_cmd(['hg', 'commit', '-m', 'test'], cwd=remote) apply_and_push(self.wc, self.repodir, lambda r, a: c(r, a, self.repodir), max_attempts=2) self.assertEquals(getRevisions(self.wc), getRevisions(self.repodir))
def testApplyAndPushFail(self): clone(self.repodir, self.wc) def c(repo, attempt, remote): run_cmd(["hg", "tag", "-f", "TEST"], cwd=repo) run_cmd(["hg", "tag", "-f", "CONFLICTING_TAG"], cwd=remote) self.assertRaises( HgUtilError, apply_and_push, self.wc, self.repodir, lambda r, a: c(r, a, self.repodir), max_attempts=2 )
def testPushNewBranchesNotAllowed(self): clone(self.repodir, self.wc, revision=self.revisions[0], clone_by_rev=True) self.assertRaises(Exception, push, self.repodir, self.wc, push_new_branches=False)
def testApplyAndPushForce(self): clone(self.repodir, self.wc) def c(repo, attempt, remote, local): run_cmd(['touch', 'newfile'], cwd=remote) run_cmd(['hg', 'add', 'newfile'], cwd=remote) run_cmd(['hg', 'commit', '-m', '"add newfile"'], cwd=remote) run_cmd(['touch', 'newfile'], cwd=local) run_cmd(['hg', 'add', 'newfile'], cwd=local) run_cmd(['hg', 'commit', '-m', '"re-add newfile"'], cwd=local) apply_and_push(self.wc, self.repodir, (lambda r, a: c(r, a, self.repodir, self.wc)), force=True)
def testPullRevision(self): # Clone just the first rev clone(self.repodir, self.wc, revision=self.revisions[-1], update_dest=False, clone_by_rev=True) self.assertEquals(getRevisions(self.wc), self.revisions[-1:]) # Now pull in just the last revision rev = pull(self.repodir, self.wc, revision=self.revisions[0], update_dest=False) self.assertEquals(rev, None) # We'll be missing the middle revision (on another branch) self.assertEquals(getRevisions(self.wc), self.revisions[:1] + self.revisions[2:])
def testApplyAndPushWithRebase(self): clone(self.repodir, self.wc) def c(repo, attempt, remote): run_cmd(["hg", "tag", "-f", "TEST"], cwd=repo) if attempt == 1: run_cmd(["hg", "rm", "hello.txt"], cwd=remote) run_cmd(["hg", "commit", "-m", "test"], cwd=remote) apply_and_push(self.wc, self.repodir, lambda r, a: c(r, a, self.repodir), max_attempts=2) self.assertEquals(getRevisions(self.wc), getRevisions(self.repodir))
def testCloneBranch(self): clone(self.repodir, self.wc, branch='branch2', update_dest=False, clone_by_rev=True) # On hg 1.6, we should only have a subset of the revisions if hg_ver() >= (1, 6, 0): self.assertEquals(self.revisions[1:], getRevisions(self.wc)) else: self.assertEquals(self.revisions, getRevisions(self.wc))
def testApplyAndPushForceFail(self): clone(self.repodir, self.wc) def c(repo, attempt, remote, local): run_cmd(['touch', 'newfile'], cwd=remote) run_cmd(['hg', 'add', 'newfile'], cwd=remote) run_cmd(['hg', 'commit', '-m', '"add newfile"'], cwd=remote) run_cmd(['touch', 'newfile'], cwd=local) run_cmd(['hg', 'add', 'newfile'], cwd=local) run_cmd(['hg', 'commit', '-m', '"re-add newfile"'], cwd=local) self.assertRaises(HgUtilError, apply_and_push, self.wc, self.repodir, (lambda r, a: c(r, a, self.repodir, self.wc)), force=False)
def testApplyAndPushForce(self): clone(self.repodir, self.wc) def c(repo, attempt, remote, local): run_cmd(["touch", "newfile"], cwd=remote) run_cmd(["hg", "add", "newfile"], cwd=remote) run_cmd(["hg", "commit", "-m", '"add newfile"'], cwd=remote) run_cmd(["touch", "newfile"], cwd=local) run_cmd(["hg", "add", "newfile"], cwd=local) run_cmd(["hg", "commit", "-m", '"re-add newfile"'], cwd=local) apply_and_push(self.wc, self.repodir, (lambda r, a: c(r, a, self.repodir, self.wc)), force=True)
def testPullUnrelated(self): # Create a new repo repo2 = os.path.join(self.tmpdir, "repo2") run_cmd(["%s/init_hgrepo.sh" % os.path.dirname(__file__), repo2]) self.assertNotEqual(self.revisions, getRevisions(repo2)) # Clone the original repo clone(self.repodir, self.wc, update_dest=False) # Try and pull in changes from the new repo self.assertRaises(subprocess.CalledProcessError, pull, repo2, self.wc, update_dest=False)
def testApplyAndPushRebaseFails(self): clone(self.repodir, self.wc) def c(repo, attempt, remote): run_cmd(['hg', 'tag', '-f', 'TEST'], cwd=repo) if attempt in (1, 2): run_cmd(['hg', 'tag', '-f', 'CONFLICTING_TAG'], cwd=remote) apply_and_push(self.wc, self.repodir, lambda r, a: c(r, a, self.repodir), max_attempts=3) self.assertEquals(getRevisions(self.wc), getRevisions(self.repodir))
def testPullUnrelated(self): # Create a new repo repo2 = os.path.join(self.tmpdir, 'repo2') run_cmd(['%s/init_hgrepo.sh' % os.path.dirname(__file__), repo2]) self.assertNotEqual(self.revisions, getRevisions(repo2)) # Clone the original repo clone(self.repodir, self.wc, update_dest=False) # Try and pull in changes from the new repo self.assertRaises(subprocess.CalledProcessError, pull, repo2, self.wc, update_dest=False)
def testCloneUpdateBranch(self): rev = clone(self.repodir, os.path.join(self.tmpdir, 'wc'), branch="branch2", update_dest=True, clone_by_rev=True) self.assertEquals(rev, self.revisions[1], self.revisions)
def testCloneWithMirror(self): mirror = os.path.join(self.tmpdir, 'repo2') clone(self.repodir, mirror) # Create a commit in the original repo open(os.path.join(self.repodir, 'test.txt'), 'w').write('hello!') run_cmd(['hg', 'add', 'test.txt'], cwd=self.repodir) run_cmd(['hg', 'commit', '-m', 'adding changeset'], cwd=self.repodir) # Now clone from the mirror clone(self.repodir, self.wc, mirrors=[mirror]) # We'll be missing the new revision from repodir self.assertNotEquals(getRevisions(self.repodir), getRevisions(self.wc)) # But we should have everything from the mirror self.assertEquals(getRevisions(mirror), getRevisions(self.wc)) # Our default path should point to the original repo though. self.assertEquals(self.repodir, path(self.wc))
def testPullWithBadMirror(self): mirror = os.path.join(self.tmpdir, 'repo2') # Now clone from the original clone(self.repodir, self.wc) # Create a new commit in the original repo open(os.path.join(self.repodir, 'test.txt'), 'w').write('hello!') run_cmd(['hg', 'add', 'test.txt'], cwd=self.repodir) run_cmd(['hg', 'commit', '-m', 'adding changeset'], cwd=self.repodir) # Pull using the mirror pull(self.repodir, self.wc, mirrors=[mirror]) self.assertEquals(getRevisions(self.wc), getRevisions(self.repodir)) # Our default path should point to the original repo self.assertEquals(self.repodir, path(self.wc))
def testMercurialByRevWithShareAndMirror(self): # First create the mirror mirror = os.path.join(self.tmpdir, 'repo2') clone(self.repodir, mirror) shareBase = os.path.join(self.tmpdir, 'share') sharerepo = os.path.join(shareBase, self.repodir.lstrip("/")) os.mkdir(shareBase) mercurial(self.repodir, self.wc, shareBase=shareBase, mirrors=[mirror], clone_by_rev=True, revision=self.revisions[-1]) # We should only have the one revision self.assertEquals(getRevisions(sharerepo), self.revisions[-1:]) self.assertEquals(getRevisions(self.wc), self.revisions[-1:])
def testPullBranch(self): # Clone just the first rev clone(self.repodir, self.wc, revision=self.revisions[-1], update_dest=False, clone_by_rev=True) self.assertEquals(getRevisions(self.wc), self.revisions[-1:]) # Now pull in the other branch rev = pull(self.repodir, self.wc, branch="branch2", update_dest=False) self.assertEquals(rev, None) # On hg 1.6, we'll be missing the last revision (on another branch) if hg_ver() >= (1, 6, 0): self.assertEquals(getRevisions(self.wc), self.revisions[1:]) else: self.assertEquals(getRevisions(self.wc), self.revisions)