示例#1
0
 def test_gitflow_pull_existing_branch_creates_non_tracking_branch(self):
     gitflow = GitFlow(self.repo).init()
     # create local branch based on first commit
     new_branch = self.repo.create_head('feat/even', 'stable')
     new_branch.checkout()
     gitflow.pull('feature', 'my-remote', 'even')
     self.assertEqual(self.repo.active_branch.name, 'feat/even')
     self.assertEqual(self.repo.active_branch.tracking_branch(), None)
示例#2
0
 def test_gitflow_init_cloned_creates_master_and_develop(self):
     heads_before_init = [h.name for h in self.repo.heads]
     self.assertNotIn('stable', heads_before_init)
     self.assertNotIn('devel', heads_before_init)
     GitFlow(self.repo).init()
     heads_after_init = [h.name for h in self.repo.heads]
     self.assertIn('stable', heads_after_init)
     self.assertIn('devel', heads_after_init)
示例#3
0
 def test_has_merge_conflict(self):
     gitflow = GitFlow(self.repo).init()
     repo = gitflow.repo
     repo.refs['devel'].checkout()
     repo.git.merge('feat/recursion')
     # the next merge creates the merge conflict
     self.assertRaises(GitCommandError, repo.git.merge, 'feat/even')
     self.assertRaises(MergeConflict, gitflow.require_no_merge_conflict)
示例#4
0
 def test_gitflow_status_on_cloned_sample_repo(self):
     gitflow = GitFlow(self.repo)
     # NB: only the active branch is created locally when cloning
     self.assertEqual(self.remote.active_branch.name, 'feat/recursion')
     self.assertItemsEqual([
         ('feat/recursion', '54d59c872469c7bf34d540d2fb3128a97502b73f',
          True),
     ], gitflow.status())
示例#5
0
 def test_gitflow_init_inits_underlying_git_repo(self):
     sandbox = create_sandbox(self)
     gitflow = GitFlow(sandbox)
     dot_git_dir = os.path.join(sandbox, '.git')
     self.assertFalse(os.path.exists(dot_git_dir))
     gitflow.init()
     self.assertTrue(os.path.exists(dot_git_dir))
     self.assertTrue(gitflow.is_initialized())
示例#6
0
 def test_delete_current_release_raises_error(self):
     gitflow = GitFlow(self.repo)
     mgr = ReleaseBranchManager(gitflow)
     mgr.create('1.0').checkout()
     self.assertRaisesRegexp(
         GitCommandError,
         'Cannot delete the branch .* which you are currently on',
         mgr.delete, '1.0')
示例#7
0
 def run_list(args):
     gitflow = GitFlow()
     gitflow.start_transaction()
     gitflow.list('feature',
                  'name',
                  use_tagname=False,
                  verbose=args.verbose,
                  include_remote=args.all)
示例#8
0
    def test_create_release_changes_active_branch(self):
        repo = create_git_repo(self)
        gitflow = GitFlow(repo).init()
        mgr = ReleaseBranchManager(gitflow)

        self.assertEquals('develop', repo.active_branch.name)
        mgr.create('1.0')
        self.assertEquals('release/1.0', repo.active_branch.name)
示例#9
0
    def test_create_new_release_from_alt_base(self):
        gitflow = GitFlow(self.repo)
        mgr = ReleaseBranchManager(gitflow)

        new_branch = mgr.create(
            '1.0', 'c8b6deac7ef94f078a426d52c0b1fb3e1221133c')  # devel~1
        self.assertEqual(new_branch.commit.hexsha,
                         'c8b6deac7ef94f078a426d52c0b1fb3e1221133c')
示例#10
0
 def test_create_new_release_branch_non_default_prefix(self):
     gitflow = GitFlow(self.repo).init()
     mgr = ReleaseBranchManager(gitflow)
     new_branch = mgr.create('3.14-beta5')
     self.assertEqual(new_branch.name, 'rel/3.14-beta5')
     self.assertIn('rel/3.14-beta5', [b.name for b in mgr.list()])
     self.assertEqual(new_branch.commit,
                      gitflow.repo.branches['devel'].commit)
示例#11
0
 def test_gitflow_pull_existing_branch_while_on_other_branchtype_raises_error(
         self):
     gitflow = GitFlow(self.repo).init()
     # create local branch based on first commit
     self.repo.create_head('feat/even', 'stable')
     self.assertRaisesRegexp(
         SystemExit, "To avoid unintended merges, git-flow aborted.",
         gitflow.pull, 'feature', 'my-remote', 'even')
示例#12
0
 def _test_create_branches_from_alt_base(self):
     repo = create_git_repo(self)
     gitflow = GitFlow(repo).init()
     gitflow.create('feature', 'foo', 'master', fetch=False)
     self.assertIn('feature/foo', [h.name for h in gitflow.repo.branches])
     gitflow.repo.index.commit('Foo')
     gitflow.create('release', '1.0', 'feature/foo', fetch=False)
     self.assertIn('release/1.0', [h.name for h in gitflow.repo.branches])
示例#13
0
 def test_create_new_feature_branch_non_default_prefix(self):
     gitflow = GitFlow(self.repo).init()
     mgr = FeatureBranchManager(gitflow)
     new_branch = mgr.create('foo')
     self.assertEqual(new_branch.name, 'feat/foo')
     self.assertIn('feat/foo', [b.name for b in mgr.list()])
     self.assertEqual(new_branch.commit,
                      gitflow.repo.branches['devel'].commit)
示例#14
0
 def test_feature_finish_rebase(self):
     gitflow = GitFlow('.').init()
     gitflow.develop().checkout()
     fake_commit(gitflow.repo, 'A commit on devel')
     runGitFlow('feature', 'finish', 'even', '--rebase')
     self.assertNotIn('feat/even', Repo().branches)
     self.assertEqual(gitflow.develop().commit.message,
                      'Finished feature even.\n')
示例#15
0
 def test_by_nameprefix_not_unique_enough(self):
     gitflow = GitFlow()
     mgr = ReleaseBranchManager(gitflow)
     # Create branch without manager since manager enforces there
     # is a single release branch.
     self.repo.create_head('rel/1.1', 'HEAD')
     self.assertRaises(PrefixNotUniqueError, mgr.by_name_prefix, '1.')
     self.assertRaises(NoSuchBranchError, mgr.by_name_prefix, 'nonexisting')
示例#16
0
 def run(args):
     gitflow = GitFlow()
     for name, hexsha, is_active_branch in gitflow.status():
         if is_active_branch:
             prefix = '*'
         else:
             prefix = ' '
         info('%s %s: %s' % (prefix, name, hexsha[:7]))
示例#17
0
    def test_gitflow_publish_creates_sets_tracking_branch(self):
        gitflow = GitFlow(self.repo).init()
        gitflow.create('feature', 'circular', 'devel', fetch=False)
        gitflow.publish('feature', 'circular')

        self.assertTrue(self.repo.branches['feat/circular'].tracking_branch())
        self.assertTrue(
            self.repo.branches['feat/circular'].tracking_branch().name,
            'my-remote/feat/circular')
示例#18
0
 def test_gitflow_pull_while_on_same_branchtype_raises_error(self):
     gitflow = GitFlow(self.repo).init()
     # activate some feature branch
     new_branch = self.repo.create_head('feat/something', 'stable')
     new_branch.checkout()
     # try to pull another feature branch
     self.assertRaisesRegexp(
         SystemExit, "To avoid unintended merges, git-flow aborted.",
         gitflow.pull, 'feature', 'my-remote', 'my-name-is-irrelevant')
示例#19
0
    def test_finish_fetch_does_not_change_repo(self):
        remote = GitFlow(self.remote).init()
        rc0 = remote.develop().commit
        gitflow = GitFlow(self.repo).init()
        c0 = gitflow.develop().commit
        self.assertEqual(rc0, c0)

        gitflow.create('feature', 'wow-feature', base=None, fetch=False)
        c1 = gitflow.develop().commit
        self.assertEqual(c0, c1)

        gitflow.finish('feature', 'wow-feature', True, False, False, False,
                       None)
        c2 = gitflow.develop().commit
        self.assertEqual(c0, c2)

        fh = self.__get_fetch_head(self.repo)
        self.assertEqual(fh, c0)
示例#20
0
 def test_finish_unresolved_merge_conflict(self):
     gitflow = GitFlow(self.repo).init()
     gitflow.finish('feature', 'recursion', False, False, False, False,
                    None)
     self.assertRaises(MergeError, gitflow.finish, 'feature', 'even', False,
                       False, False, False, None)
     # do not resolve, but finish again
     self.assertRaises(Usage, gitflow.finish, 'feature', 'even', False,
                       False, False, False, None)
示例#21
0
 def test_gitflow_name_or_current_returns_name(self):
     gitflow = GitFlow(self.repo).init()
     # gitflow.init checks out `devel` branch :-(
     self.repo.branches['feat/recursion'].checkout()
     self.assertEqual('even', gitflow.name_or_current('feature', 'even'))
     self.assertEqual(
         'xxxx', gitflow.name_or_current('feature',
                                         'xxxx',
                                         must_exist=False))
示例#22
0
    def test_gitflow_init_cloned_creates_branches_from_counterpart(self):
        remote = GitFlow(self.remote)
        rmc0 = remote.master().commit
        rdc0 = remote.develop().commit

        gitflow = GitFlow(self.repo).init()
        mc0 = gitflow.master().commit
        dc0 = gitflow.develop().commit

        # local and remote heads must be the same
        self.assertEqual(rmc0, mc0)
        self.assertEqual(rdc0, dc0)
        self.assertTrue(gitflow.master().tracking_branch())
        self.assertTrue(gitflow.develop().tracking_branch())
        self.assertEqual(gitflow.master().tracking_branch().name,
                         'my-remote/stable')
        self.assertEqual(gitflow.develop().tracking_branch().name,
                         'my-remote/devel')
示例#23
0
 def test_gitflow_init_cloned_creates_no_custom_master_and_develop(self):
     heads_before_init = [h.name for h in self.repo.heads]
     self.assertNotIn('foo', heads_before_init)
     self.assertNotIn('bar', heads_before_init)
     gitflow = GitFlow(self.repo)
     self.assertRaises(NotImplementedError,
                       gitflow.init,
                       master='foo',
                       develop='bar')
示例#24
0
 def test_gitflow_status_on_remote_sample_repo(self):
     gitflow = GitFlow(self.remote)
     self.assertItemsEqual([
         ('stable', '296586bb164c946cad10d37e82570f60e6348df9', False),
         ('devel', '2b34cd2e1617e5f0d4e077c6ec092b9f50ed49a3', False),
         ('feat/recursion', '54d59c872469c7bf34d540d2fb3128a97502b73f',
          True),
         ('feat/even', 'e56be18dada9e81ca7969760ddea357b0c4c9412', False),
     ], gitflow.status())
示例#25
0
    def test_finish_feature_push_keep(self):
        gitflow = GitFlow(self.repo).init()
        mgr = FeatureBranchManager(gitflow)
        mgr.create('even')
        mgr.finish('even', push=True, keep=True)

        # Finishing removes the local and the remote feature branch
        self.assertIn('feat/even', [b.name for b in self.repo.branches])
        self.assertIn('feat/even', [b.name for b in self.remote.branches])
示例#26
0
 def test_finish_feature_unresolved_merge_conflict(self):
     gitflow = GitFlow(self.repo).init()
     mgr = FeatureBranchManager(gitflow)
     mgr.finish('recursion')
     self.assertRaises(MergeError,
                       mgr.finish, 'even')
     # do not resolve, but finish again
     self.assertRaises(GitCommandError,
                       mgr.finish, 'even')
示例#27
0
    def test_detect_branch_types(self):
        create_git_repo(self)
        gitflow = GitFlow()

        # The types that "ship" with git-flow
        self.assertIn('feature', gitflow.managers)
        self.assertIn('release', gitflow.managers)
        self.assertIn('hotfix', gitflow.managers)
        self.assertIn('support', gitflow.managers)
示例#28
0
 def test_feature_list_verbose_no_commits(self):
     repo = create_git_repo(self)
     gitflow = GitFlow(repo).init()
     repo.create_head('feature/wow', 'HEAD')
     stdout = runGitFlow('feature', 'list', '--verbose', capture=1)
     expected = [
       '  wow (no commits yet)'
       ]
     self.assertEqual(stdout.splitlines(), expected)
示例#29
0
 def test_empty_branch_type_list_raises_usage(self):
     create_git_repo(self)
     gitflow = GitFlow().init()
     self.assertRaises(Usage, gitflow.list, 'feature', 'name', False, False)
     self.assertRaises(Usage, gitflow.list, 'release', 'version', False,
                       False)
     self.assertRaises(Usage, gitflow.list, 'hotfix', 'version', False,
                       False)
     self.assertRaises(Usage, gitflow.list, 'support', 'version', False,
                       False)
示例#30
0
    def test_detect_custom_branch_types(self):
        create_git_repo(self)

        # Declare a custom branch type inline
        class FooBarManager(BranchManager):
            identifier = 'foobar'
            DEFAULT_PREFIX = 'xyz/'

        gitflow = GitFlow()
        self.assertIn('foobar', gitflow.managers)