def test_update(self):
        hgrepo = hglib.open(self.main_repo)
        tip = Changeset(None, hgrepo.tip())
        repo = Repository(self.main_repo)
        repo.update(tip)

        self.assertEquals(hgrepo.parents()[0].node, tip.hash)
    def test_commit_commits_all(self):
        repo = hglib.open(self.main_repo)

        file_name = "f1"
        file_path = os.path.join(self.main_repo, file_name)
        expected_content = "changed content"
        with open(file_path, "w+") as file:
            file.write("foo test content")
        commit_msg = "Test message"
        repo.add(file_path)
        repo.commit('Creating file', user="******")
        with open(file_path, "w+") as file:
            file.write(expected_content)

        repository = Repository(self.main_repo)
        repository.commit(commit_msg)

        with open(file_path, "w+") as file:
            file.write('content changed again')

        repo.update(clean=True)

        with open(file_path) as file:
            self.assertEquals(expected_content, file.read())

        repo.close()
    def test_get_revset(self):
        repo = Repository(self.main_repo)

        self.assertEquals(len(list(
            repo.get_revset(cs_from="branch(integration)"))), 3)
        self.assertEquals(len(list(
            repo.get_revset(cs_from="0", cs_to="tip"))), 5)
示例#4
0
    def test_update(self):
        hgrepo = hglib.open(self.main_repo)
        tip = Changeset(None, hgrepo.tip())
        repo = Repository(self.main_repo)
        repo.update(tip)

        self.assertEquals(hgrepo.parents()[0].node, tip.hash)
示例#5
0
    def test_commit_commits_all(self):
        repo = hglib.open(self.main_repo)

        file_name = "f1"
        file_path = os.path.join(self.main_repo, file_name)
        expected_content = "changed content"
        with open(file_path, "w+") as file:
            file.write("foo test content")
        commit_msg = "Test message"
        repo.add(file_path)
        repo.commit('Creating file', user="******")
        with open(file_path, "w+") as file:
            file.write(expected_content)

        repository = Repository(self.main_repo)
        repository.commit(commit_msg)

        with open(file_path, "w+") as file:
            file.write('content changed again')

        repo.update(clean=True)

        with open(file_path) as file:
            self.assertEquals(expected_content, file.read())

        repo.close()
示例#6
0
    def test_get_revset(self):
        repo = Repository(self.main_repo)

        self.assertEquals(
            len(list(repo.get_revset(cs_from="branch(integration)"))), 3)
        self.assertEquals(len(list(repo.get_revset(cs_from="0", cs_to="tip"))),
                          5)
 def test_create_branch(self):
     clon = hglib.open(os.path.join(self.environment_path, 'repo1'))
     clon.update('default')
     hgrepo = Repository(os.path.join(self.environment_path, 'repo1'))
     hgcs = Changeset(hgrepo, clon.tip())
     branch = hgcs.create_branch('fakebranch')
     self.assertEquals(branch.get_changeset(), hgrepo.tip())
     self.assertEquals('fakebranch', clon.branch())
     clon.close()
 def test_create_branch(self):
     clon = hglib.open(os.path.join(self.environment_path, 'repo1'))
     clon.update('default')
     hgrepo = Repository(os.path.join(self.environment_path, 'repo1'))
     hgcs = Changeset(hgrepo, clon.tip())
     branch = hgcs.create_branch('fakebranch')
     self.assertEquals(branch.get_changeset(), hgrepo.tip())
     self.assertEquals('fakebranch', clon.branch())
     clon.close()
 def test_get_changeset_tags(self):
     hgrepo = hglib.open(self.main_repo)
     hgrepo.update()
     rev = hgrepo.tip().node
     hgrepo.tag("test_tag", rev=rev, user='******')
     hgrepo.tag("test_tag2", rev=rev, user='******')
     repo = Repository(self.main_repo)
     tags = repo.get_changeset_tags(rev)
     self.assertListEqual(tags, ["test_tag", "test_tag2"])
     hgrepo.close()
示例#10
0
 def test_get_changeset_tags(self):
     hgrepo = hglib.open(self.main_repo)
     hgrepo.update()
     rev = hgrepo.tip().node
     hgrepo.tag("test_tag", rev=rev, user='******')
     hgrepo.tag("test_tag2", rev=rev, user='******')
     repo = Repository(self.main_repo)
     tags = repo.get_changeset_tags(rev)
     self.assertListEqual(tags, ["test_tag", "test_tag2"])
     hgrepo.close()
示例#11
0
 def test_strip(self):
     hgrepo = hglib.open(self.main_repo)
     hgrepo.update(rev=INITIAL_BRANCH)
     rev = self.commit_in_repo(self.main_repo, ['f199'],
                               ['extra commit'])[1]
     repo = Repository(self.main_repo)
     repo.strip(repo[rev])
     with self.assertRaises(hglib.error.CommandError):
         hgrepo.log(revrange=rev)
     hgrepo.close()
 def test_strip(self):
     hgrepo = hglib.open(self.main_repo)
     hgrepo.update(rev=INITIAL_BRANCH)
     rev = self.commit_in_repo(self.main_repo, ['f199'],
                               ['extra commit'])[1]
     repo = Repository(self.main_repo)
     repo.strip(repo[rev])
     with self.assertRaises(hglib.error.CommandError):
         hgrepo.log(revrange=rev)
     hgrepo.close()
示例#13
0
    def test_get_branch_tip(self):
        repo = hglib.open(self.main_repo)
        branch = repo.branch()
        tip = repo.log(branch=branch, limit=1)[0][1]
        repo.close()
        repository = Repository(self.main_repo)
        self.assertEquals(repository.get_branch_tip(branch).hash, tip)

        with self.assertRaises(RepositoryError):
            repository.get_branch_tip("inexistent_branch")
    def test_get_branch_tip(self):
        repo = hglib.open(self.main_repo)
        branch = repo.branch()
        tip = repo.log(branch=branch, limit=1)[0][1]
        repo.close()
        repository = Repository(self.main_repo)
        self.assertEquals(repository.get_branch_tip(branch).hash, tip)

        with self.assertRaises(RepositoryError):
            repository.get_branch_tip("inexistent_branch")
示例#15
0
    def test_commit_without_allow_empty_does_not_fail_when_no_changes(self):
        repo = hglib.open(self.main_repo)
        initial_len = len(repo.log())
        commit_msg = 'foo message'

        repository = Repository(self.main_repo)
        result = repository.commit(commit_msg)

        self.assertIsNone(result)
        self.assertEquals(len(repo.log()), initial_len)
        repo.close()
    def test_commit_without_allow_empty_does_not_fail_when_no_changes(self):
        repo = hglib.open(self.main_repo)
        initial_len = len(repo.log())
        commit_msg = 'foo message'

        repository = Repository(self.main_repo)
        result = repository.commit(commit_msg)

        self.assertIsNone(result)
        self.assertEquals(len(repo.log()), initial_len)
        repo.close()
示例#17
0
    def test_compare_branches(self):
        test1 = 'test1'

        hgrepo = hglib.open(self.main_repo)
        hgrepo.update(rev=INITIAL_BRANCH)
        hgrepo.branch(test1)
        self.commit_in_repo(self.main_repo, ['f199', 'f99'],
                            ['extra commit', 'another extra commit'])
        repo = Repository(self.main_repo)
        diff = repo.compare_branches(test1, INITIAL_BRANCH)
        self.assertEquals(2, len(diff))
        hgrepo.close()
    def test_compare_branches(self):
        test1 = 'test1'

        hgrepo = hglib.open(self.main_repo)
        hgrepo.update(rev=INITIAL_BRANCH)
        hgrepo.branch(test1)
        self.commit_in_repo(self.main_repo, ['f199', 'f99'],
                            ['extra commit', 'another extra commit'])
        repo = Repository(self.main_repo)
        diff = repo.compare_branches(test1, INITIAL_BRANCH)
        self.assertEquals(2, len(diff))
        hgrepo.close()
    def test_get_branch_no_name(self):
        repo = Repository(self.main_repo)

        hgrepo = hglib.open(self.main_repo)
        hgrepo.close()
        branch = repo.get_branch()

        self.assertEquals(branch.name, "test_branch")
        changesets_list = [x for x in repo.get_revset(branch=branch.name)]
        self.assertEquals(len(changesets_list), 2)
        self.assertEquals(
            changesets_list[0].desc, "#TICKET-2 yet another commit")
        self.assertEquals(changesets_list[1].desc, "TICKET-1 one commit")
示例#20
0
    def test_commit_commits_all_but_removed_files(self):
        file_name = "f1"
        file_path = os.path.join(self.main_repo, file_name)
        commit_msg = "Test message"

        repository = Repository(self.main_repo)
        os.remove(file_path)
        repository.commit(commit_msg)

        hglibrepo = hglib.open(self.main_repo)
        hglibrepo.branch(clean=True)

        self.assertFalse(os.path.exists(file_path))
    def test_commit_commits_all_but_removed_files(self):
        file_name = "f1"
        file_path = os.path.join(self.main_repo, file_name)
        commit_msg = "Test message"

        repository = Repository(self.main_repo)
        os.remove(file_path)
        repository.commit(commit_msg)

        hglibrepo = hglib.open(self.main_repo)
        hglibrepo.branch(clean=True)

        self.assertFalse(os.path.exists(file_path))
示例#22
0
    def test_get_branch_no_name(self):
        repo = Repository(self.main_repo)

        hgrepo = hglib.open(self.main_repo)
        hgrepo.close()
        branch = repo.get_branch()

        self.assertEquals(branch.name, "test_branch")
        changesets_list = [x for x in repo.get_revset(branch=branch.name)]
        self.assertEquals(len(changesets_list), 2)
        self.assertEquals(changesets_list[0].desc,
                          "#TICKET-2 yet another commit")
        self.assertEquals(changesets_list[1].desc, "TICKET-1 one commit")
示例#23
0
    def test_merge(self):
        repo = hglib.open(self.main_repo)
        repository = Repository(self.main_repo)
        orig_rev = repo.tip()[1]
        commits = ['extra commit', '#INT-00 another extra commit']
        self.commit_in_repo(self.main_repo, ['f1', 'f2'], commits)
        new_rev = repository[repo.tip()[1]]
        repo.update(rev=orig_rev)
        self.commit_in_repo(self.main_repo, ['f3', ' f4'], [
            'extra commit in another branch',
            'another extra commit in another branch'
        ])
        third_revision = repository[repo.tip()[1]]

        # need to commit, return true
        repository.merge(other_rev=new_rev)
        cs = repository["tip"]
        self.assertEquals(len(cs.parents), 2)
        repo.update(third_revision, clean=True)
        self.commit_in_repo(
            self.main_repo, ['f1', 'f2'],
            ['this should conflict', 'this should conflict too'])
        # conflicts
        with self.assertRaises(RepositoryError):
            repository.merge(new_rev)

        with self.assertRaises(RepositoryError):
            # this calls send_mail, what raises exception
            # TODO: use stubs
            repository.merge("wrong_revision")
        repo.close()
    def test_full_merge_and_push(self):
        repo_path = os.path.join(self.environment_path, "mergepush")
        self.clone_repo(repo_path, self.main_repo, revision="tip")
        base_branch = "integration"
        origin = self.main_repo
        destination = 'http://push.fake'
        repo = hglib.open(repo_path)
        repo.branch(base_branch)
        # Let's merge with an ancestor so the push is not performed
        hash = 1

        repo = Repository(self.main_repo)
        repo.full_merge_and_push(base_branch, hash, 'fake_branch', origin,
                                 destination)
示例#25
0
    def test_full_merge_and_push(self):
        repo_path = os.path.join(self.environment_path, "mergepush")
        self.clone_repo(repo_path, self.main_repo, revision="tip")
        base_branch = "integration"
        origin = self.main_repo
        destination = 'http://push.fake'
        repo = hglib.open(repo_path)
        repo.branch(base_branch)
        # Let's merge with an ancestor so the push is not performed
        hash = 1

        repo = Repository(self.main_repo)
        repo.full_merge_and_push(base_branch, hash, 'fake_branch',
                                 origin, destination)
    def test_branch(self):
        repo = Repository(self.main_repo)
        repo.branch("new-branch")
        hgrepo = hglib.open(self.main_repo)
        self.assertEquals(hgrepo.branch(), "new-branch")
        hgrepo.close()

        # this does not throw exception, even though the branch already exists,
        # because it is forced
        repo.branch(INITIAL_BRANCH)

        hgrepo = hglib.open(self.main_repo)
        self.assertEquals(hgrepo.branch(), INITIAL_BRANCH)
        hgrepo.close()
    def test_is_merge(self):
        test1 = 'test1'

        hgrepo = hglib.open(self.main_repo)
        hgrepo.update(rev=INITIAL_BRANCH)
        hgrepo.branch(test1)
        self.commit_in_repo(self.main_repo, ['f199', 'f99'],
                            ['extra commit', 'another extra commit'])

        hgrepo.update(rev='test_branch')
        hgrepo.merge(rev=test1)
        rev = hgrepo.commit(message="merge", user="******")[1]
        repo = Repository(self.main_repo)
        self.assertTrue(repo.is_merge(rev))
        hgrepo.close()
示例#28
0
    def test_is_merge(self):
        test1 = 'test1'

        hgrepo = hglib.open(self.main_repo)
        hgrepo.update(rev=INITIAL_BRANCH)
        hgrepo.branch(test1)
        self.commit_in_repo(self.main_repo, ['f199', 'f99'],
                            ['extra commit', 'another extra commit'])

        hgrepo.update(rev='test_branch')
        hgrepo.merge(rev=test1)
        rev = hgrepo.commit(message="merge", user="******")[1]
        repo = Repository(self.main_repo)
        self.assertTrue(repo.is_merge(rev))
        hgrepo.close()
 def test___str__(self):
     clon = hglib.open(os.path.join(self.environment_path, 'repo1'))
     clon.update('default')
     hgrepo = Repository(os.path.join(self.environment_path, 'repo1'))
     hgcs = Changeset(hgrepo, clon.tip())
     self.assertEquals(hgcs.__str__(),
                       clon.tip().node[:Changeset.SHORT_HASH_COUNT])
示例#30
0
    def test_get_ancestor(self):
        repo_main = hglib.open(self.main_repo)
        orig_rev = repo_main.tip()
        commits_integration = [
            'commit in integration', 'another extra commit in integration'
        ]
        self.commit_in_repo(self.main_repo, ['f1', 'f2'], commits_integration)
        rev1 = repo_main.tip()
        repo_main.update(rev="tip~%i" % len(commits_integration))
        repo_main.branch("other-branch")
        commits = [
            'commit in other-branch', 'another extra commit in other-branch'
        ]
        self.commit_in_repo(self.main_repo, ['f3', 'f2'], commits)
        rev2 = repo_main.tip()
        repo_main.update(rev=orig_rev[1])

        repo = Repository(self.main_repo)
        ancestor = repo.get_ancestor(repo[rev1[1]], repo[rev2[1]])

        self.assertEquals(ancestor.hash, orig_rev[1])
        repo_main.close()

        with self.assertRaises(RepositoryError):
            repo.get_ancestor(None, repo[rev2[1]])

        with self.assertRaises(RepositoryError):
            repo.get_ancestor(repo["bad_revision"], repo["another"])
    def test_merge(self):
        repo = hglib.open(self.main_repo)
        repository = Repository(self.main_repo)
        orig_rev = repo.tip()[1]
        commits = ['extra commit', '#INT-00 another extra commit']
        self.commit_in_repo(self.main_repo, ['f1', 'f2'], commits)
        new_rev = repository[repo.tip()[1]]
        repo.update(rev=orig_rev)
        self.commit_in_repo(
            self.main_repo,
            ['f3', ' f4'],
            [
                'extra commit in another branch',
                'another extra commit in another branch'
            ])
        third_revision = repository[repo.tip()[1]]

        # need to commit, return true
        repository.merge(other_rev=new_rev)
        cs = repository["tip"]
        self.assertEquals(len(cs.parents), 2)
        repo.update(third_revision, clean=True)
        self.commit_in_repo(
            self.main_repo, ['f1', 'f2'],
            ['this should conflict', 'this should conflict too'])
        # conflicts
        with self.assertRaises(RepositoryError):
            repository.merge(new_rev)

        with self.assertRaises(RepositoryError):
            # this calls send_mail, what raises exception
            # TODO: use stubs
            repository.merge("wrong_revision")
        repo.close()
示例#32
0
    def test_commit(self):
        repo = hglib.open(self.main_repo)
        initial_len = len(repo.log())
        file_name = "test_file"
        file_path = os.path.join(self.main_repo, file_name)
        with open(file_path, "a") as file:
            file.write("test content")
        commit_msg = "Test message"
        repo.add(file_path)

        repository = Repository(self.main_repo)
        repository.commit(commit_msg)

        self.assertEquals(len(repo.log()), initial_len + 1)
        self.assertEquals(repo.tip()[5], commit_msg)
        repo.close()

        self.assertIsNone(repository.commit(commit_msg))
    def test_commit(self):
        repo = hglib.open(self.main_repo)
        initial_len = len(repo.log())
        file_name = "test_file"
        file_path = os.path.join(self.main_repo, file_name)
        with open(file_path, "a") as file:
            file.write("test content")
        commit_msg = "Test message"
        repo.add(file_path)

        repository = Repository(self.main_repo)
        repository.commit(commit_msg)

        self.assertEquals(len(repo.log()), initial_len + 1)
        self.assertEquals(repo.tip()[5], commit_msg)
        repo.close()

        self.assertIsNone(repository.commit(commit_msg))
 def test_init(self):
     clon = hglib.open(os.path.join(self.environment_path, 'repo1'))
     hgrepo = Repository(os.path.join(self.environment_path, 'repo1'))
     hgcs = Changeset(hgrepo, clon.tip())
     clon.close()
     self.assertEquals(hgcs.author, "Jose Plana <*****@*****.**>")
     self.assertEquals(hgcs.hash,
                       "c377d40d21153bdcc4ec0b24bba48af3899fcc7c")
     self.assertEquals(hgcs.desc, "Second changeset")
     self.assertFalse(hgcs.merge)
     self.assertEquals(hgcs.parents[0].hash,
                       "b93d349f220d892047817f7ab29b2e8bfc5569ba")
示例#35
0
    def test_pull(self):
        self.commit_in_repo(self.main_repo, ['f1', 'f2'],
                            ['extra commit', 'another extra commit'])

        repo_main = hglib.open(self.main_repo)
        second_repo = hglib.open(self.second_repo)
        self.assertNotEqual(len(repo_main.log()), len(second_repo.log()))
        repo = Repository(self.second_repo)
        repo.pull(remote=self.main_repo)

        self.assertEquals(len(repo_main.log()), len(second_repo.log()))

        repo_main.close()
        second_repo.close()
        repo = Repository(self.second_repo)

        with self.assertRaises(RepositoryError):
            repo.pull(revision="tip", remote="wrong_repo")

        with self.assertRaises(RepositoryError):
            repo.pull(revision="none_revision", remote=self.main_repo)
    def test_get_ancestor(self):
        repo_main = hglib.open(self.main_repo)
        orig_rev = repo_main.tip()
        commits_integration = ['commit in integration',
                               'another extra commit in integration']
        self.commit_in_repo(self.main_repo, ['f1', 'f2'], commits_integration)
        rev1 = repo_main.tip()
        repo_main.update(rev="tip~%i" % len(commits_integration))
        repo_main.branch("other-branch")
        commits = ['commit in other-branch',
                   'another extra commit in other-branch']
        self.commit_in_repo(self.main_repo, ['f3', 'f2'], commits)
        rev2 = repo_main.tip()
        repo_main.update(rev=orig_rev[1])

        repo = Repository(self.main_repo)
        ancestor = repo.get_ancestor(repo[rev1[1]], repo[rev2[1]])

        self.assertEquals(ancestor.hash, orig_rev[1])
        repo_main.close()

        with self.assertRaises(RepositoryError):
            repo.get_ancestor(None, repo[rev2[1]])

        with self.assertRaises(RepositoryError):
            repo.get_ancestor(repo["bad_revision"], repo["another"])
    def test_add_files(self):
        file_name = "absurd_file"
        file_path = os.path.join(self.main_repo, file_name)
        with open(file_path, "w") as file:
            file_content = "Absurd content"
            file.write(file_content)
        repo_main = hglib.open(self.main_repo)
        with self.assertRaises(hglib.error.CommandError):
            repo_main.cat([file_path], rev="tip")

        status = repo_main.status()[0][0]
        repo_main.close()
        self.assertEquals(status, "?")
        repo = Repository(self.main_repo)
        repo.add(file_name)
        repo_main = hglib.open(self.main_repo)
        status = repo_main.status()[0][0]
        repo_main.close()
        self.assertEquals(status, "A")

        with self.assertRaises(RepositoryError):
            repo.add("nonexistentfile")
    def test_push(self):
        repo = hglib.open(self.main_repo)
        repo.update(rev=INITIAL_BRANCH)
        self.commit_in_repo(
            self.main_repo, ['f1', 'f2'], ['TICKET-10', 'TICKET-11'])
        self.commit_in_repo(
            self.second_repo, ['f3', 'f4'], ['TICKET-12', 'TICKET-13'])

        repo2 = Repository(self.second_repo)

        with self.assertRaises(RepositoryError):
            repo2.push(
                self.main_repo,
                self.main_repo,
                Changeset(None, (1, "inexistent_rev", None, None, None, None)))

        with self.assertRaises(RepositoryError):
            repo2.push(self.main_repo, "inexistent_destination")

        repo2.push(self.main_repo, self.main_repo)

        logs = [changeset[5] for changeset in repo.log()]
        self.assertTrue('TICKET-10' in logs)
        self.assertTrue('TICKET-11' in logs)
        self.assertTrue('TICKET-12' in logs)
        self.assertTrue('TICKET-13' in logs)

        repo.update()
        self.commit_in_repo(
            self.main_repo, ['f3', 'f4'], ['TICKET-10', 'TICKET-11'])
        self.commit_in_repo(
            self.second_repo, ['f3', 'f4'], ['TICKET-12', 'TICKET-13'])

        repo.close()
        # now with conflicts
        with self.assertRaises(RepositoryError):
            repo2.push(self.main_repo, self.main_repo, repo2.tip())
示例#39
0
    def test_branch(self):
        repo = Repository(self.main_repo)
        repo.branch("new-branch")
        hgrepo = hglib.open(self.main_repo)
        self.assertEquals(hgrepo.branch(), "new-branch")
        hgrepo.close()

        # this does not throw exception, even though the branch already exists,
        # because it is forced
        repo.branch(INITIAL_BRANCH)

        hgrepo = hglib.open(self.main_repo)
        self.assertEquals(hgrepo.branch(), INITIAL_BRANCH)
        hgrepo.close()
    def test_pull(self):
        self.commit_in_repo(self.main_repo, ['f1', 'f2'],
                                            ['extra commit',
                                             'another extra commit'])

        repo_main = hglib.open(self.main_repo)
        second_repo = hglib.open(self.second_repo)
        self.assertNotEqual(len(repo_main.log()), len(second_repo.log()))
        repo = Repository(self.second_repo)
        repo.pull(remote=self.main_repo)

        self.assertEquals(len(repo_main.log()), len(second_repo.log()))

        repo_main.close()
        second_repo.close()
        repo = Repository(self.second_repo)

        with self.assertRaises(RepositoryError):
            repo.pull(revision="tip", remote="wrong_repo")

        with self.assertRaises(RepositoryError):
            repo.pull(revision="none_revision", remote=self.main_repo)
示例#41
0
    def test_terminate_branch(self):
        repo_path = self.create_repo(self.environment_path,
                                     repo_name="terminate_branch_test")

        branch_name = "TEST_BRANCH"

        repo = hglib.open(repo_path)
        repo.branch(branch_name)
        file_name = "test_file"
        file_path = os.path.join(repo_path, file_name)

        with open(file_path, "a") as file:
            file.write("test content")

        commit_msg = "Test message"
        repo.add(file_path)

        repository = Repository(repo_path)
        repository.commit(commit_msg)

        self.assertEquals(len(repo.branches()), 2)
        self.assertEquals(len(repo.branches(active=True)), 1)
        self.assertEquals(len(repo.branches(closed=True)), 2)

        self.mox.StubOutWithMock(repository, "push")
        repository.terminate_branch(branch_name, None, None)

        self.assertEquals(len(repo.branches()), 1)
        self.assertEquals(len(repo.branches(active=True)), 0)
        self.assertEquals(len(repo.branches(closed=True)), 2)

        # Closing branch already closed
        # it shouldn't do anything but warning with a message
        repository.terminate_branch(branch_name, None, None)

        repo.close()
示例#42
0
    def test_terminate_branch(self):
        repo_path = self.create_repo(self.environment_path,
                                     repo_name="terminate_branch_test")

        branch_name = "TEST_BRANCH"

        repo = hglib.open(repo_path)
        repo.branch(branch_name)
        file_name = "test_file"
        file_path = os.path.join(repo_path, file_name)

        with open(file_path, "a") as file:
            file.write("test content")

        commit_msg = "Test message"
        repo.add(file_path)

        signature = Signature(user='******')

        repository = Repository(repo_path)
        repository.commit(commit_msg, signature)

        self.assertEquals(len(repo.branches()), 2)
        self.assertEquals(len(repo.branches(active=True)), 1)
        self.assertEquals(len(repo.branches(closed=True)), 2)

        self.mox.StubOutWithMock(repository, "push")
        repository.terminate_branch(branch_name, signature, None, None)

        self.assertEquals(len(repo.branches()), 1)
        self.assertEquals(len(repo.branches(active=True)), 0)
        self.assertEquals(len(repo.branches(closed=True)), 2)

        # Closing branch already closed
        # it shouldn't do anything but warning with a message
        repository.terminate_branch(branch_name, signature, None, None)

        repo.close()
示例#43
0
    def test_add_files(self):
        file_name = "absurd_file"
        file_path = os.path.join(self.main_repo, file_name)
        with open(file_path, "w") as file:
            file_content = "Absurd content"
            file.write(file_content)
        repo_main = hglib.open(self.main_repo)
        with self.assertRaises(hglib.error.CommandError):
            repo_main.cat([file_path], rev="tip")

        status = repo_main.status()[0][0]
        repo_main.close()
        self.assertEquals(status, "?")
        repo = Repository(self.main_repo)
        repo.add(file_name)
        repo_main = hglib.open(self.main_repo)
        status = repo_main.status()[0][0]
        repo_main.close()
        self.assertEquals(status, "A")

        with self.assertRaises(RepositoryError):
            repo.add("nonexistentfile")
示例#44
0
    def test_commit_with_allow_empty_fails_when_no_changes(self):
        commit_msg = 'foo message'

        repository = Repository(self.main_repo)
        with self.assertRaises(RepositoryError):
            repository.commit(commit_msg, allow_empty=True)
示例#45
0
 def test_get_branches(self):
     repo = hglib.open(self.main_repo)
     repository = Repository(self.main_repo)
     branches = [b.name for b in repository.get_branches()]
     self.assertListEqual(branches, [b[0] for b in repo.branches()])
     repo.close()
 def test_get_branches(self):
     repo = hglib.open(self.main_repo)
     repository = Repository(self.main_repo)
     branches = [b.name for b in repository.get_branches()]
     self.assertListEqual(branches, [b[0] for b in repo.branches()])
     repo.close()
示例#47
0
    def test_push(self):
        repo = hglib.open(self.main_repo)
        repo.update(rev=INITIAL_BRANCH)
        self.commit_in_repo(self.main_repo, ['f1', 'f2'],
                            ['TICKET-10', 'TICKET-11'])
        self.commit_in_repo(self.second_repo, ['f3', 'f4'],
                            ['TICKET-12', 'TICKET-13'])

        repo2 = Repository(self.second_repo)

        with self.assertRaises(RepositoryError):
            repo2.push(
                self.main_repo, self.main_repo,
                Changeset(None, (1, "inexistent_rev", None, None, None, None)))

        with self.assertRaises(RepositoryError):
            repo2.push(self.main_repo, "inexistent_destination")

        repo2.push(self.main_repo, self.main_repo)

        logs = [changeset[5] for changeset in repo.log()]
        self.assertTrue('TICKET-10' in logs)
        self.assertTrue('TICKET-11' in logs)
        self.assertTrue('TICKET-12' in logs)
        self.assertTrue('TICKET-13' in logs)

        repo.update()
        self.commit_in_repo(self.main_repo, ['f3', 'f4'],
                            ['TICKET-10', 'TICKET-11'])
        self.commit_in_repo(self.second_repo, ['f3', 'f4'],
                            ['TICKET-12', 'TICKET-13'])

        repo.close()
        # now with conflicts
        with self.assertRaises(RepositoryError):
            repo2.push(self.main_repo, self.main_repo, repo2.tip())
    def test_parents(self):
        hgrepo = hglib.open(self.main_repo)
        repo = Repository(self.main_repo)

        self.assertEquals([cs.node for cs in hgrepo.parents()],
                          [cs.hash for cs in repo.parents()])
示例#49
0
    def test_parents(self):
        hgrepo = hglib.open(self.main_repo)
        repo = Repository(self.main_repo)

        self.assertEquals([cs.node for cs in hgrepo.parents()],
                          [cs.hash for cs in repo.parents()])
 def test_tag(self):
     repo = Repository(self.main_repo)
     repo.tag("new-tag", message="fake tag")
     hgrepo = hglib.open(self.main_repo)
     self.assertEquals(hgrepo.tags()[1][0], "new-tag")
     hgrepo.close()
 def test_get_branch_doesnt_exist(self):
     repo = Repository(self.main_repo)
     hgrepo = hglib.open(self.main_repo)
     hgrepo.close()
     with self.assertRaises(RepositoryError):
         repo.get_branch('this_does_not_exist')
    def test_commit_with_allow_empty_fails_when_no_changes(self):
        commit_msg = 'foo message'

        repository = Repository(self.main_repo)
        with self.assertRaises(RepositoryError):
            repository.commit(commit_msg, allow_empty=True)
示例#53
0
 def test_get_branch_doesnt_exist(self):
     repo = Repository(self.main_repo)
     hgrepo = hglib.open(self.main_repo)
     hgrepo.close()
     with self.assertRaises(RepositoryError):
         repo.get_branch('this_does_not_exist')
示例#54
0
 def test_tag(self):
     repo = Repository(self.main_repo)
     repo.tag("new-tag", message="fake tag")
     hgrepo = hglib.open(self.main_repo)
     self.assertEquals(hgrepo.tags()[1][0], "new-tag")
     hgrepo.close()