Esempio n. 1
0
def test_stash_error():
    """ Run 'git up' with an error while stashing """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()
Esempio n. 2
0
def test_bundler():
    """ Run bundler integration """
    shell = True if platform.system() == 'Windows' else False

    if os.environ.get('TRAVIS', False):
        raise SkipTest('Skip this test on Travis CI :(')

    # Helper methods
    def is_installed(prog):
        dev_null = open(os.devnull, 'wb')
        return_value = subprocess.call([prog, '--version'],
                                       shell=shell,
                                       stdout=dev_null,
                                       stderr=dev_null)
        return return_value == 0

    def get_output(cmd):
        return subprocess.check_output(cmd, shell=shell)

    # Check for ruby and bundler
    if not (is_installed('ruby') and is_installed('gem')
            and 'bundler' in get_output(['gem', 'list'])):

        # Ruby not installed, skip test
        raise SkipTest('Ruby not installed, skipped Bundler integration test')

    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()
Esempio n. 3
0
def test_unstash_error():
    """ Run 'git up' with an unclean unstash """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()
Esempio n. 4
0
def test_fetch_fail():
    """ Run 'git up' with a non-existent remote """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()
Esempio n. 5
0
def test_bundler():
    """ Run bundler integration """
    shell = True if platform.system() == 'Windows' else False

    if os.environ.get('TRAVIS', False):
        raise SkipTest('Skip this test on Travis CI :(')

    # Helper methods
    def is_installed(prog):
        dev_null = open(os.devnull, 'wb')
        try:
            return_value = subprocess.call([prog, '--version'], shell=shell,
                                           stdout=dev_null, stderr=dev_null)
            return return_value == 0
        except OSError:
            return False

    def get_output(cmd):
        return str(subprocess.check_output(cmd, shell=shell))

    # Check for ruby and bundler
    if not (is_installed('ruby') and is_installed('gem')
            and 'bundler' in get_output(['gem', 'list'])):

        # Ruby not installed, skip test
        raise SkipTest('Ruby not installed, skipped Bundler integration test')

    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()
Esempio n. 6
0
def test_detached():
    """ Run 'git up' with detached head """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()
Esempio n. 7
0
def test_rebase_error():
    """ Run 'git up' with a failing rebase """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()
Esempio n. 8
0
def test_submodules():
    """ Run 'git up' with submodules """
    repo = Repo(repo_path)
    repo_head = repo.head.commit.hexsha
    submod_head = repo.submodules[0].hexsha

    os.chdir(join(repo_path, 'sub'))

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)

    # PyGitUp uses the submodule instead of the toplevel git repo
    assert_equal(submod_head, gitup.git.repo.head.commit.hexsha)

    gitup.run()

    repo = Repo(repo_path)

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'fast-forwarding')

    # Repo itself is unchanged:
    assert_equal(repo.head.commit.hexsha, repo_head)
    # Submodule is changed:
    assert_not_equal(gitup.git.repo.head.commit.hexsha, submod_head)
Esempio n. 9
0
def test_checkout_error():
    """ Run 'git up' with checkout errors """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()
Esempio n. 10
0
def test_submodules():
    """ Run 'git up' with submodules """
    repo = Repo(repo_path)
    repo_head = repo.head.commit.hexsha
    submod_head = repo.submodules[0].hexsha

    os.chdir(join(repo_path, 'sub'))

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)

    # PyGitUp uses the submodule instead of the toplevel git repo
    assert submod_head == gitup.git.repo.head.commit.hexsha

    gitup.run()

    repo = Repo(repo_path)

    assert len(gitup.states) == 1
    assert gitup.states[0] == 'fast-forwarding'

    # Repo itself is unchanged:
    assert repo.head.commit.hexsha, repo_head
    # Submodule is changed:
    assert gitup.git.repo.head.commit.hexsha != submod_head
Esempio n. 11
0
def test_rebase_error():
    """ Run 'git up' with a failing rebase """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()
def test_fast_forwarded():
    """ Fail correctly when a rebase would overwrite untracked files """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)

    gitup.run()
Esempio n. 13
0
def test_out_of_tree():
    """ Run 'git up' with an out-of-tree source """
    os.chdir(work_tree)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(gitup.states, ['fast-forwarding'])
Esempio n. 14
0
def test_out_of_tree():
    """ Run 'git up' with an out-of-tree source """
    os.chdir(work_tree)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert gitup.states == ['fast-forwarding']
Esempio n. 15
0
def test_detached():
    """ Run 'git up' with detached head """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)

    with pytest.raises(GitError):
        gitup.run()
def test_ahead_of_upstream():
    """ Run 'git up' with result: ahead of upstream """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'ahead')
Esempio n. 17
0
def test_fast_forwarded():
    """ Run 'git up' with result: fast-forwarding """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'fast-forwarding')
def test_remote_branch_deleted():
    """ Run 'git up' with remotely deleted branch """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 2)
    assert_equal(gitup.states[1], 'remote branch doesn\'t exist')
Esempio n. 19
0
def test_rebasing():
    """ Run 'git up' with result: rebasing """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert len(gitup.states) == 1
    assert gitup.states[0] == 'rebasing'
Esempio n. 20
0
def test_issue_55():
    """ Regression test for #55 """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'fast-forwarding')
Esempio n. 21
0
def test_diverged():
    """ Run 'git up' with result: diverged """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'diverged')
Esempio n. 22
0
def test_up_to_date():
    """ Run 'git up' with result: up to date """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'up to date')
Esempio n. 23
0
def test_ahead_of_upstream():
    """ Run 'git up' with result: ahead of upstream """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert len(gitup.states) == 1
    assert gitup.states[0] == 'ahead'
Esempio n. 24
0
def test_log_hook():
    """ Run 'git up' with log-hook"""
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'fast-forwarding')
Esempio n. 25
0
def test_fast_forwarded():
    """ Run 'git up' with result: fast-forwarding """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert len(gitup.states) == 1
    assert gitup.states[0] == 'fast-forwarding'
Esempio n. 26
0
def test_rebase_arguments():
    """ Run 'git up' with rebasing.arguments """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'rebasing')
Esempio n. 27
0
def test_tracking():
    """ Run 'git up' with a local tracking branch """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'fast-forwarding')
Esempio n. 28
0
def test_fast_forwarded():
    """ Run 'git up' with multiple remotes """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 2)
    assert_equal(gitup.states[0], 'fast-forwarding')
    assert_equal(gitup.states[1], 'fast-forwarding')
def test_returning_to_branch():
    """ Run 'git up': return to branch """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'fast-forwarding')
    assert_equal(gitup.repo.head.ref.name, new_branch_name)
Esempio n. 30
0
def test_rebasing():
    """ Run 'git up' with pushing to origin """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.settings['push.auto'] = True
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'rebasing')
    assert_equal(gitup.pushed, True)
Esempio n. 31
0
def test_rebase_arguments():
    """ Run 'git up' with rebasing.arguments """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)

    with pytest.raises(RebaseError):
        gitup.run()

    assert len(gitup.states) == 1
    assert gitup.states[0] == 'rebasing'
Esempio n. 32
0
def test_rebasing():
    """ Run 'git up' with pushing to origin """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.settings['push.auto'] = True
    gitup.run()

    assert len(gitup.states) == 1
    assert gitup.states[0] == 'rebasing'
    assert gitup.pushed
Esempio n. 33
0
def test_run_in_subdir():
    """ Run 'git up' in a subdir of the repo """
    subdir = join(repo_path, 'dir')
    os.mkdir(subdir)
    os.chdir(subdir)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'fast-forwarding')
Esempio n. 34
0
def test_separate_worktree():
    """ Run 'git up' with separate work tree """
    if Git().version_info[:3] < (2, 5, 1):
        raise SkipTest('Skip this test on Travis CI :(')

    os.chdir(worktree_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert len(gitup.states) == 1
    assert gitup.states[0] == 'fast-forwarding'
Esempio n. 35
0
def test_separate_worktree():
    """ Run 'git up' with separate work tree """
    if Git().version_info[:3] < (2, 5, 1):
        raise SkipTest("Skip this test on Travis CI :(")

    os.chdir(worktree_path)

    from PyGitUp.gitup import GitUp

    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], "fast-forwarding")
Esempio n. 36
0
def test_fetchall():
    """ Run 'git up' with fetch.all """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)

    with capture() as [stdout, _]:
        gitup.run()

    stdout = stdout.getvalue()

    assert_true('origin' in stdout)
    assert_true(test_name in stdout)
Esempio n. 37
0
def test_no_remotes():
    """ Run 'git up' w/o remotes """
    os.chdir(master_path)

    from PyGitUp.gitup import GitUp

    with pytest.raises(GitError):
        GitUp(testing=True)
Esempio n. 38
0
def test_submodules_dirty():
    """ Run 'git up' with submodules in a dirty repo """
    repo = Repo(repo_path)
    repo_head = repo.head.commit.hexsha
    submod_head = repo.submodules[0].hexsha

    # Change file in submodule
    write_file('sub/file', 'submodule changed')

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)

    # PyGitUp uses the main repo
    assert_equal(repo_head, gitup.git.repo.head.commit.hexsha)

    gitup.run()

    assert_equal(len(gitup.states), 1)
    assert_equal(gitup.states[0], 'rebasing')
Esempio n. 39
0
def test_no_fetch():
    """ Run 'git up' with '--no-fetch' argument """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.should_fetch = False

    with capture() as [stdout, _]:
        gitup.run()

    stdout = stdout.getvalue()

    assert_false('Fetching' in stdout)

    assert_true('rebasing' in stdout)
    assert_true('up to date' in stdout)
    assert_true(test_name in stdout)
    assert_true(new_branch_name in stdout)
def test_faster_forwarded():
    """ Run 'git up' with result: (fast) fast-forwarding """
    os.chdir(repo_path)

    assert_not_equal(master.branches[test_name].commit,
                     repo.branches[test_name].commit)
    assert_not_equal(master.branches[test_name].commit, 
                     repo.branches[test_name + '.2'].commit)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()

    assert_equal(len(gitup.states), 2)
    assert_equal(gitup.states[0], 'fast-forwarding')
    assert_equal(gitup.states[1], 'fast-forwarding')
    assert_equal(master.branches[test_name].commit,
                 repo.branches[test_name].commit)
    assert_equal(master.branches[test_name].commit, 
                 repo.branches[test_name + '.2'].commit)
Esempio n. 41
0
def test_bundler():
    """ Run bundler integration """
    if os.environ.get('TRAVIS', False):
        raise SkipTest('Skip this test on Travis CI :(')

    def is_installed(prog):
        dev_null = open(os.devnull, 'wb')
        return_value = subprocess.call([prog, '--version'], shell=True,
                                       stdout=dev_null, stderr=dev_null)
        return return_value == 0

    if not (is_installed('ruby') and is_installed('gem')):
        # Ruby not installed, skip test
        raise SkipTest('Ruby not installed, skipped Bundler integration test')

    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.run()