def test_merge_isuptodate(self):
     gitrepo = Repository(self.cloned_from_repo)
     gitrepo.update('master')
     uptodate_hash = '52109e71fd7f16cb366acfcbb140d6d7f2fc50c9'
     cs = gitrepo[uptodate_hash]
     should_be_none = gitrepo.merge(other_rev=cs)
     self.assertIsNone(should_be_none)
 def test_merge_isuptodate(self):
     gitrepo = Repository(self.cloned_from_repo)
     gitrepo.update('master')
     uptodate_hash = '52109e71fd7f16cb366acfcbb140d6d7f2fc50c9'
     cs = gitrepo[uptodate_hash]
     should_be_none = gitrepo.merge(other_rev=cs)
     self.assertIsNone(should_be_none)
 def test_get_branch(self):
     repo = Repository(self.cloned_from_repo)
     branch = repo.get_branch('newbranch')
     self.assertEquals(branch.name, 'newbranch')
     repo.update('newbranch')
     branch = repo.get_branch()
     self.assertEquals(branch.name, 'newbranch')
     with self.assertRaises(RepositoryError):
         branch = repo.get_branch('does_not_exist')
Example #4
0
 def test_merge_no_conflicts(self):
     git = GitCmd(self.cloned_from_repo)
     headnewbranch = git('rev-parse', 'refs/heads/newbranch')
     gitrepo = Repository(self.cloned_from_repo)
     # Checkout to master
     gitrepo.update('master')
     cs = gitrepo.merge(other_rev=gitrepo[headnewbranch])
     self.assertEquals(len(git('log', '-1', pretty='%P').split()), 2)
     self.assertEquals(git('rev-parse', 'HEAD'), cs.hash)
 def test_get_branch(self):
     repo = Repository(self.cloned_from_repo)
     branch = repo.get_branch('newbranch')
     self.assertEquals(branch.name, 'newbranch')
     repo.update('newbranch')
     branch = repo.get_branch()
     self.assertEquals(branch.name, 'newbranch')
     with self.assertRaises(RepositoryError):
         branch = repo.get_branch('does_not_exist')
 def test_is_merge(self):
     git = GitCmd(self.cloned_from_repo)
     headnewbranch = git('show-ref', '-s', 'refs/heads/newbranch')
     gitrepo = Repository(self.cloned_from_repo)
     self.assertFalse(gitrepo.is_merge(git('rev-parse', 'HEAD')))
     # Do a merge
     gitrepo.update('master')
     merge_rev = gitrepo.merge(other_rev=gitrepo[headnewbranch])
     self.assertTrue(gitrepo.is_merge(merge_rev.hash))
    def test_update_failures(self):
        repo_name = 'fixture-3'
        self.add_content_to_repo(
            os.path.join(FIXTURE_PATH, 'fixture-3.git.bundle'),
            os.path.join(self.environment_path, repo_name))
        gitrepo = Repository(os.path.join(self.environment_path, repo_name))

        with self.assertRaises(RepositoryError):
            gitrepo.update("doesntexist")
 def test_is_merge(self):
     git = GitCmd(self.cloned_from_repo)
     headnewbranch = git('show-ref', '-s', 'refs/heads/newbranch')
     gitrepo = Repository(self.cloned_from_repo)
     self.assertFalse(gitrepo.is_merge(git('rev-parse', 'HEAD')))
     # Do a merge
     gitrepo.update('master')
     merge_rev = gitrepo.merge(other_rev=gitrepo[headnewbranch])
     self.assertTrue(gitrepo.is_merge(merge_rev.hash))
    def test_update_failures(self):
        repo_name = 'fixture-3'
        self.add_content_to_repo(
            os.path.join(FIXTURE_PATH, 'fixture-3.git.bundle'),
            os.path.join(self.environment_path, repo_name))
        gitrepo = Repository(os.path.join(self.environment_path, repo_name))

        with self.assertRaises(RepositoryError):
            gitrepo.update("doesntexist")
 def test_merge_no_conflicts(self):
     repo = pygit2.Repository(self.cloned_from_repo)
     headnewbranch = repo.lookup_reference(
         'refs/remotes/origin/newbranch').get_object().hex
     gitrepo = Repository(self.cloned_from_repo)
     # Checkout to master
     gitrepo.update('master')
     cs = gitrepo.merge(other_rev=gitrepo[headnewbranch])
     self.assertEquals(len(repo.head.get_object().parents), 2)
     self.assertEquals(repo.head.get_object().hex, cs.hash)
    def test_no_notes_go_fine(self):
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo.update('master')
        changeset = gitrepo.commit('A new commit!', allow_empty=True)

        notes = gitrepo.get_changeset_notes(changeset.hash)
        self.assertEqual([], notes)

        notes = gitrepo.get_changeset_notes()
        self.assertEqual([], notes)
    def test_merge_no_conflicts(self):
        git = GitCmd(self.cloned_from_repo)

        headnewbranch = git('rev-parse', 'refs/heads/newbranch')
        gitrepo = Repository(self.cloned_from_repo)
        # Checkout to master
        gitrepo.update('master')
        cs = gitrepo.merge(other_rev=gitrepo[headnewbranch])
        self.assertEquals(len(git('log', '-1', pretty='%P').split()), 2)
        self.assertEquals(git('rev-parse', 'HEAD'), cs.hash)
 def test_commit_custom_parent(self):
     gitrepo = Repository(self.main_repo)
     gitrepo.update('master')
     c1 = gitrepo.commit('A commit', allow_empty=True)
     c2 = gitrepo.commit('Other commit', allow_empty=True)
     gitrepo.commit('Commit with custom parent', allow_empty=True,
         custom_parent=c1.hash)
     self.assertEquals(
         [p.hash for p in gitrepo.parents()],
         [c2.hash, c1.hash])
    def test_no_notes_go_fine(self):
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo.update('master')
        changeset = gitrepo.commit('A new commit!', allow_empty=True)

        notes = gitrepo.get_changeset_notes(changeset.hash)
        self.assertEqual([], notes)

        notes = gitrepo.get_changeset_notes()
        self.assertEqual([], notes)
 def test_commit_custom_parent(self):
     gitrepo = Repository(self.main_repo)
     gitrepo.update('master')
     c1 = gitrepo.commit('A commit', allow_empty=True)
     c2 = gitrepo.commit('Other commit', allow_empty=True)
     gitrepo.commit('Commit with custom parent',
                    allow_empty=True,
                    custom_parent=c1.hash)
     self.assertEquals([p.hash for p in gitrepo.parents()],
                       [c2.hash, c1.hash])
 def test_is_merge(self):
     repo = pygit2.Repository(self.cloned_from_repo)
     reference = repo.lookup_reference('refs/remotes/origin/newbranch')
     headnewbranch = reference.get_object().hex
     gitrepo = Repository(self.cloned_from_repo)
     self.assertFalse(gitrepo.is_merge(repo.head.get_object().hex))
     # Do a merge
     gitrepo.update('master')
     merge_rev = gitrepo.merge(other_rev=gitrepo[headnewbranch])
     self.assertTrue(gitrepo.is_merge(merge_rev.hash))
    def test_update(self):
        repo_name = 'fixture-3'
        path = os.path.join(self.environment_path, repo_name)
        self.add_content_to_repo(
            os.path.join(FIXTURE_PATH, 'fixture-3.git.bundle'), path)
        git = GitCmd(path)
        gitrepo = Repository(path)

        gitrepo.update("master")
        self.assertFalse(os.path.isfile(os.path.join(path, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(path, 'file1.txt')))
        self.assertFalse(os.path.isfile(os.path.join(path, 'file3.txt')))
        self.assertNotEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'HEAD')

        gitrepo.update("branch-1")
        self.assertTrue(os.path.isfile(os.path.join(path, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(path, 'file1.txt')))
        self.assertFalse(os.path.isfile(os.path.join(path, 'file3.txt')))
        self.assertNotEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'HEAD')

        gitrepo.update("branch-2")
        self.assertTrue(os.path.isfile(os.path.join(path, 'file3.txt')))
        self.assertFalse(os.path.isfile(os.path.join(path, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(path, 'file1.txt')))
        self.assertNotEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'HEAD')

        gitrepo.update("08b952ae66e59b216b1171c0c57082353bc80863")
        self.assertFalse(os.path.isfile(os.path.join(path, 'file3.txt')))
        self.assertFalse(os.path.isfile(os.path.join(path, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(path, 'file1.txt')))
        self.assertEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'HEAD')
    def test_commit_commits_but_with_removed_files(self):
        file_name = "test1.txt"
        file_path = os.path.join(self.main_repo, file_name)
        commit_msg = "Test message"

        gitrepo = Repository(self.main_repo)
        gitrepo.update('master')
        os.remove(file_path)
        git = GitCmd(self.main_repo)

        gitrepo.commit(commit_msg)
        git('reset', hard=True)

        self.assertTrue(os.path.exists(file_path))
    def test_update(self):
        repo_name = 'fixture-3'
        path = os.path.join(self.environment_path, repo_name)
        self.add_content_to_repo(
            os.path.join(FIXTURE_PATH, 'fixture-3.git.bundle'),
            path)
        git = GitCmd(path)
        gitrepo = Repository(path)

        gitrepo.update("master")
        self.assertFalse(os.path.isfile(os.path.join(path, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(path, 'file1.txt')))
        self.assertFalse(os.path.isfile(os.path.join(path, 'file3.txt')))
        self.assertNotEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'HEAD')

        gitrepo.update("branch-1")
        self.assertTrue(os.path.isfile(os.path.join(path, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(path, 'file1.txt')))
        self.assertFalse(os.path.isfile(os.path.join(path, 'file3.txt')))
        self.assertNotEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'HEAD')

        gitrepo.update("branch-2")
        self.assertTrue(os.path.isfile(os.path.join(path, 'file3.txt')))
        self.assertFalse(os.path.isfile(os.path.join(path, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(path, 'file1.txt')))
        self.assertNotEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'HEAD')

        gitrepo.update("08b952ae66e59b216b1171c0c57082353bc80863")
        self.assertFalse(os.path.isfile(os.path.join(path, 'file3.txt')))
        self.assertFalse(os.path.isfile(os.path.join(path, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(path, 'file1.txt')))
        self.assertEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'HEAD')
    def test_commit_commits_but_with_removed_files(self):
        file_name = "test1.txt"
        file_path = os.path.join(self.main_repo, file_name)
        commit_msg = "Test message"

        gitrepo = Repository(self.main_repo)
        gitrepo.update('master')
        os.remove(file_path)
        git = GitCmd(self.main_repo)

        gitrepo.commit(commit_msg)
        git('reset', hard=True)

        self.assertTrue(os.path.exists(file_path))
    def test_append_get_and_has_notes(self):
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo.update('master')
        changeset = gitrepo.commit('A new commit!', allow_empty=True)

        gitrepo.append_note('Hello note 1', revision=changeset.hash)
        gitrepo.append_note('Goodbye note 2')

        notes = gitrepo.get_changeset_notes(changeset.hash)
        self.assertEqual(['Hello note 1', 'Goodbye note 2'], notes)

        self.assertTrue(gitrepo.has_note('Hello note 1'))
        self.assertTrue(gitrepo.has_note('Goodbye note 2', changeset.hash))
        self.assertFalse(gitrepo.has_note(''))
        self.assertFalse(gitrepo.has_note('\n'))
    def test_append_get_and_has_notes(self):
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo.update('master')
        changeset = gitrepo.commit('A new commit!', allow_empty=True)

        gitrepo.append_note('Hello note 1', revision=changeset.hash)
        gitrepo.append_note('Goodbye note 2')

        notes = gitrepo.get_changeset_notes(changeset.hash)
        self.assertEqual(['Hello note 1', 'Goodbye note 2'], notes)

        self.assertTrue(gitrepo.has_note('Hello note 1'))
        self.assertTrue(gitrepo.has_note('Goodbye note 2', changeset.hash))
        self.assertFalse(gitrepo.has_note(''))
        self.assertFalse(gitrepo.has_note('\n'))
    def test_commit_commits_but_with_removed_files(self):
        file_name = "test1.txt"
        file_path = os.path.join(self.main_repo, file_name)
        commit_msg = "Test message"

        gitrepo = Repository(self.main_repo)
        gitrepo.update('master')
        os.remove(file_path)
        gitrepo.commit(commit_msg)

        repo = pygit2.Repository(self.main_repo)
        repo.reset(repo.head.target.hex, pygit2.GIT_RESET_HARD)
        repo.checkout_head(strategy=(pygit2.GIT_CHECKOUT_FORCE |
                                     pygit2.GIT_CHECKOUT_REMOVE_UNTRACKED))

        self.assertTrue(os.path.exists(file_path))
    def test_merge_with_conflict(self):
        gitrepo = Repository(self.cloned_from_repo)
        # Checkout
        gitrepo.update('newbranch')
        file_to_conflict_name = 'test1.txt'
        file_to_conflict = os.path.join(self.cloned_from_repo,
                                        file_to_conflict_name)
        with open(file_to_conflict, "w") as file:
            file_content = "Absurd content"
            file.write(file_content)

        gitrepo.add(file_to_conflict_name)
        conflict_cs = gitrepo.commit("Provoking conflict")
        gitrepo.update('master')
        try:
            gitrepo.merge(other_rev=conflict_cs)
            self.fail()
        except MergeConflictError as exp:
            self.assertTrue('Conflicts found: merging test1.txt failed' in exp)
    def test_exterminate_branch(self):
        branch_name = 'newbranch'
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo_main = Repository(self.main_repo)
        gitrepo.update(branch_name)
        # Pushing the branch to the remote repo so we can check it's removed
        # remotely too
        gitrepo.push(None, self.main_repo, ref_name=branch_name)

        self.assertEquals(len(list(gitrepo.get_branches())), 2)
        self.assertEquals(len(list(gitrepo_main.get_branches())), 2)

        gitrepo.exterminate_branch(branch_name, None, self.main_repo)

        self.assertEquals(len(list(gitrepo.get_branches())), 1)
        self.assertEquals(len(list(gitrepo_main.get_branches())), 1)

        # Terminating a branch already terminated
        # it shouldn't do anything but warning with a message
        gitrepo.exterminate_branch(branch_name, None, self.main_repo)
    def test_merge_fastforward_no_ff(self):
        git = GitCmd(self.cloned_from_repo)
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo.update('master')
        gitrepo.branch('ff-branch')
        ff_file_name = 'ff-file.txt'
        ff_file = os.path.join(self.cloned_from_repo, ff_file_name)
        with open(ff_file, "w") as file:
            file_content = "Absurd content"
            file.write(file_content)
        gitrepo.add(ff_file_name)

        ff_head = gitrepo.commit(message="commit ff file")
        gitrepo.update('master')
        cs = gitrepo.merge(other_rev=ff_head, other_branch_name='test')
        self.assertEquals(len(git('log', '-1', pretty='%P').split()), 2)
        self.assertEquals(git('rev-parse', 'HEAD'), cs.hash)
        # We want a commit in fastforward merges, hashes must be different
        self.assertNotEquals(ff_head.hash, cs.hash)
        self.assertTrue(os.path.isfile(ff_file))
    def test_merge_fastforward_no_ff(self):
        repo = pygit2.Repository(self.cloned_from_repo)
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo.update('master')
        gitrepo.branch('ff-branch')
        ff_file_name = 'ff-file.txt'
        ff_file = os.path.join(self.cloned_from_repo, ff_file_name)
        with open(ff_file, "w") as file:
            file_content = "Absurd content"
            file.write(file_content)
        gitrepo.add(ff_file_name)

        ff_head = gitrepo.commit(message="commit ff file")
        gitrepo.update('master')
        cs = gitrepo.merge(other_rev=ff_head, other_branch_name='test')
        self.assertEquals(len(repo.head.get_object().parents), 2)
        self.assertEquals(repo.head.get_object().hex, cs.hash)
        # We want a commit in fastforward merges, hashes must be different
        self.assertNotEquals(ff_head.hash, cs.hash)
        self.assertTrue(os.path.isfile(ff_file))
    def test_exterminate_branch(self):
        branch_name = 'newbranch'
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo_main = Repository(self.main_repo)
        gitrepo.update(branch_name)
        # Pushing the branch to the remote repo so we can check it's removed
        # remotely too
        gitrepo.push(None, self.main_repo, ref_name=branch_name)

        self.assertEquals(len(list(gitrepo.get_branches())), 2)
        self.assertEquals(len(list(gitrepo_main.get_branches())), 4)

        gitrepo.exterminate_branch(branch_name, None, self.main_repo)

        self.assertEquals(len(list(gitrepo.get_branches())), 1)
        self.assertEquals(len(list(gitrepo_main.get_branches())), 3)

        # Terminating a branch already terminated
        # it shouldn't do anything but warning with a message
        gitrepo.exterminate_branch(branch_name, None, self.main_repo)
    def test_merge_fastforward_no_ff(self):
        git = GitCmd(self.cloned_from_repo)
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo.update('master')
        gitrepo.branch('ff-branch')
        ff_file_name = 'ff-file.txt'
        ff_file = os.path.join(self.cloned_from_repo, ff_file_name)
        with open(ff_file, "w") as file:
            file_content = "Absurd content"
            file.write(file_content)
        gitrepo.add(ff_file_name)

        ff_head = gitrepo.commit(message="commit ff file")
        gitrepo.update('master')
        cs = gitrepo.merge(other_rev=ff_head, other_branch_name='test')
        self.assertEquals(len(git('log', '-1', pretty='%P').split()), 2)
        self.assertEquals(git('rev-parse', 'HEAD'), cs.hash)
        # We want a commit in fastforward merges, hashes must be different
        self.assertNotEquals(ff_head.hash, cs.hash)
        self.assertTrue(os.path.isfile(ff_file))
    def test_merge_fastforward(self):
        repo = pygit2.Repository(self.cloned_from_repo)
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo.update('master')
        gitrepo.branch('ff-branch')
        ff_file_name = 'ff-file.txt'
        ff_file = os.path.join(self.cloned_from_repo, ff_file_name)
        with open(ff_file, "w") as file:
            file_content = "Absurd content"
            file.write(file_content)
        gitrepo.add(ff_file_name)

        signature = Signature(user="******")
        ff_head = gitrepo.commit(message="commit ff file", signature=signature)
        gitrepo.update('master')
        cs = gitrepo.merge_fastforward(
            signature, other_rev=ff_head, other_branch_name='test')
        self.assertEquals(len(repo.head.get_object().parents), 1)
        self.assertEquals(repo.head.get_object().hex, cs.hash)
        self.assertEquals(ff_head.hash, cs.hash)
        self.assertTrue(os.path.isfile(ff_file))
Example #31
0
    def test_merge_with_conflict(self):
        gitrepo = Repository(self.cloned_from_repo)
        # Checkout
        gitrepo.update('newbranch')
        file_to_conflict_name = 'test1.txt'
        file_to_conflict = os.path.join(self.cloned_from_repo,
                                        file_to_conflict_name)
        with open(file_to_conflict, "w") as file:
            file_content = "Absurd content"
            file.write(file_content)

        gitrepo.add(file_to_conflict_name)
        conflict_cs = gitrepo.commit("Provoking conflict")
        gitrepo.update('master')

        try:
            gitrepo.merge(other_rev=conflict_cs)
            self.fail('Merge with conflict should have failed')
        except MergeConflictError as exp:
            print exp
            self.assertTrue('Conflicts found: merging test1.txt failed' in exp)
    def test_update(self):
        repo_name = 'fixture-3'
        self.add_content_to_repo(
            os.path.join(FIXTURE_PATH, 'fixture-3.git.bundle'),
            os.path.join(self.environment_path, repo_name))
        gitrepo = Repository(os.path.join(self.environment_path, repo_name))

        gitrepo.update("master")
        self.assertFalse(os.path.isfile(os.path.join(self.environment_path,
                                                     repo_name, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(self.environment_path,
                                                    repo_name, 'file1.txt')))
        self.assertFalse(os.path.isfile(os.path.join(self.environment_path,
                                                     repo_name, 'file3.txt')))
        self.assertFalse(gitrepo._repository.head_is_detached)

        gitrepo.update("branch-1")
        self.assertTrue(os.path.isfile(os.path.join(self.environment_path,
                                                    repo_name, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(self.environment_path,
                                                    repo_name, 'file1.txt')))
        self.assertFalse(os.path.isfile(os.path.join(self.environment_path,
                                                     repo_name, 'file3.txt')))
        self.assertFalse(gitrepo._repository.head_is_detached)

        gitrepo.update("branch-2")
        self.assertTrue(os.path.isfile(os.path.join(self.environment_path,
                                                    repo_name, 'file3.txt')))
        self.assertFalse(os.path.isfile(os.path.join(self.environment_path,
                                                     repo_name, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(self.environment_path,
                                                    repo_name, 'file1.txt')))
        self.assertFalse(gitrepo._repository.head_is_detached)

        gitrepo.update("08b952ae66e59b216b1171c0c57082353bc80863")
        self.assertFalse(os.path.isfile(os.path.join(self.environment_path,
                                                     repo_name, 'file3.txt')))
        self.assertFalse(os.path.isfile(os.path.join(self.environment_path,
                                                     repo_name, 'file2.txt')))
        self.assertTrue(os.path.isfile(os.path.join(self.environment_path,
                                                    repo_name, 'file1.txt')))
        self.assertTrue(gitrepo._repository.head_is_detached)
    def test_get_revset(self):
        repo = pygit2.Repository(self.cloned_from_repo)
        gitrepo = Repository(self.cloned_from_repo)

        # Just cs_from
        just_from_second = gitrepo.get_revset(
            cs_from="52109e71fd7f16cb366acfcbb140d6d7f2fc50c9")
        self.assertEquals(len(list(just_from_second)), 3)

        # No params
        no_params = gitrepo.get_revset()
        self.assertEquals(len(list(no_params)), 4)

        # From first commit to head
        first_to_head = gitrepo.get_revset(
            cs_from="e3b1fc907ea8b3482e29eb91520c0e2eee2b4cdb",
            cs_to=repo.head.target.hex)
        self.assertEquals(len(list(first_to_head)), 4)
        second_to_head = gitrepo.get_revset(
            cs_from="52109e71fd7f16cb366acfcbb140d6d7f2fc50c9",
            cs_to=repo.head.target.hex)
        self.assertEquals(len(list(second_to_head)), 3)
        second_to_third = gitrepo.get_revset(
            cs_from="52109e71fd7f16cb366acfcbb140d6d7f2fc50c9",
            cs_to="2a9e1b9be3fb95ed0841aacc1f20972430dc1a5c")
        self.assertEquals(len(list(second_to_third)), 2)

        # Just by branch
        by_branch = gitrepo.get_revset(branch='newbranch')
        self.assertEquals(len(list(by_branch)), 3)

        # Just by branch being in another
        gitrepo.update('master')
        by_branch = gitrepo.get_revset(branch='newbranch')
        self.assertEquals(len(list(by_branch)), 3)
        self.assertEquals(repo.head.shorthand, 'master')

        # Only common ancestor belong to newbranch
        common_ancestor = gitrepo.get_revset(
            cs_to="b7fa61d5faf434642e35744b55d8d8f367afc343",
            cs_from="52109e71fd7f16cb366acfcbb140d6d7f2fc50c9",
            branch='newbranch')
        self.assertEquals(len(list(common_ancestor)), 1)

        # Zero changesets belong to newbranch
        none = gitrepo.get_revset(
            cs_to="b7fa61d5faf434642e35744b55d8d8f367afc343",
            cs_from="2a9e1b9be3fb95ed0841aacc1f20972430dc1a5c",
            branch='newbranch')
        self.assertEquals(len(list(none)), 0)

        # From the beginning to master tip so only common changesets in both
        # branches
        common_changesets = gitrepo.get_revset(
            cs_to="b7fa61d5faf434642e35744b55d8d8f367afc343",
            branch='newbranch')
        self.assertEquals(len(list(common_changesets)), 2)

        # From the beginning to common ancestor, that belongs to both branches
        toboth = gitrepo.get_revset(
            cs_to="52109e71fd7f16cb366acfcbb140d6d7f2fc50c9",
            branch='newbranch')
        self.assertEquals(len(list(toboth)), 2)

        # From newbranch origin to newbranch tip
        ignore_branch3 = gitrepo.get_revset(
            cs_from="e3b1fc907ea8b3482e29eb91520c0e2eee2b4cdb",
            branch='newbranch')
        self.assertEquals(len(list(ignore_branch3)), 3)
    def test_get_revset(self):
        git = GitCmd(self.cloned_from_repo)
        gitrepo = Repository(self.cloned_from_repo)

        # Just cs_from
        just_from_second = gitrepo.get_revset(
            cs_from="52109e71fd7f16cb366acfcbb140d6d7f2fc50c9")
        self.assertEquals(len(list(just_from_second)), 3)

        # No params
        no_params = gitrepo.get_revset()
        self.assertEquals(len(list(no_params)), 4)

        # From first commit to head
        first_to_head = gitrepo.get_revset(
            cs_from="e3b1fc907ea8b3482e29eb91520c0e2eee2b4cdb",
            cs_to=git('rev-parse', 'HEAD'))
        self.assertEquals(len(list(first_to_head)), 4)
        second_to_head = gitrepo.get_revset(
            cs_from="52109e71fd7f16cb366acfcbb140d6d7f2fc50c9",
            cs_to=git('rev-parse', 'HEAD'))
        self.assertEquals(len(list(second_to_head)), 3)
        second_to_third = gitrepo.get_revset(
            cs_from="52109e71fd7f16cb366acfcbb140d6d7f2fc50c9",
            cs_to="2a9e1b9be3fb95ed0841aacc1f20972430dc1a5c")
        self.assertEquals(len(list(second_to_third)), 2)

        # Just by branch
        by_branch = gitrepo.get_revset(branch='newbranch')
        self.assertEquals(len(list(by_branch)), 3)

        # Just by branch being in another
        gitrepo.update('master')
        by_branch = gitrepo.get_revset(branch='newbranch')
        self.assertEquals(len(list(by_branch)), 3)
        self.assertEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'master')

        # Only common ancestor belong to newbranch
        common_ancestor = gitrepo.get_revset(
            cs_to="b7fa61d5faf434642e35744b55d8d8f367afc343",
            cs_from="52109e71fd7f16cb366acfcbb140d6d7f2fc50c9",
            branch='newbranch')
        self.assertEquals(len(list(common_ancestor)), 1)

        # Zero changesets belong to newbranch
        none = gitrepo.get_revset(
            cs_to="b7fa61d5faf434642e35744b55d8d8f367afc343",
            cs_from="2a9e1b9be3fb95ed0841aacc1f20972430dc1a5c",
            branch='newbranch')
        self.assertEquals(len(list(none)), 0)

        # From the beginning to master tip so only common changesets in both
        # branches
        common_changesets = gitrepo.get_revset(
            cs_to="b7fa61d5faf434642e35744b55d8d8f367afc343",
            branch='newbranch')
        self.assertEquals(len(list(common_changesets)), 2)

        # From the beginning to common ancestor, that belongs to both branches
        toboth = gitrepo.get_revset(
            cs_to="52109e71fd7f16cb366acfcbb140d6d7f2fc50c9",
            branch='newbranch')
        self.assertEquals(len(list(toboth)), 2)

        # From newbranch origin to newbranch tip
        ignore_branch3 = gitrepo.get_revset(
            cs_from="e3b1fc907ea8b3482e29eb91520c0e2eee2b4cdb",
            branch='newbranch')
        self.assertEquals(len(list(ignore_branch3)), 3)