def test_get_tag_name_from_tags_throws_exception_on_no_tags(self):
        tag = 'foo'
        command_runner = CommandRunner()
        command_runner.check_output = MagicMock(return_value="")
        fzf = Fzf()
        fzf.run = MagicMock(return_value="tag\t" + tag)

        git_data_getter = GitDataGetter(fzf, command_runner)
        self.assertRaises(NoTagsException, git_data_getter.get_tag_name)
    def test_get_branch_name(self):
        branch = 'foo'
        command_runner = CommandRunner()
        command_runner.check_output = MagicMock(return_value="branch | bar")
        fzf = Fzf()
        fzf.run = MagicMock(return_value="branch\t" + branch)

        git_data_getter = GitDataGetter(fzf, command_runner)
        result = git_data_getter.get_branch_name()
        self.assertEqual(result, branch)
    def test_get_tag_name_from_tags(self):
        tag = 'foo'
        command_runner = CommandRunner()
        command_runner.check_output = MagicMock(return_value="tag | bar")
        fzf = Fzf()
        fzf.run = MagicMock(return_value="tag\t" + tag)

        git_data_getter = GitDataGetter(fzf, command_runner)
        result = git_data_getter.get_tag_name()
        self.assertEqual(result, tag)
    def test_get_commit_hash(self):
        branch = 'foo'
        commit = 'afe786e5'
        output = commit + '\t1 day ago\tFoo Bar\tSomething something commit'
        command_runner = CommandRunner()
        command_runner.check_output = MagicMock(return_value='')
        fzf = Fzf()
        fzf.run = MagicMock(return_value=output)

        git_data_getter = GitDataGetter(fzf, command_runner)
        result = git_data_getter.get_commit_hash(branch)
        self.assertEqual(result, commit)
Exemplo n.º 5
0
    def test_run(self):
        file_path = getcwd() + '/test/AddPreviewTestFile.py'
        with open(file_path, "w") as file:
            file.write('print("Hello Test")')

        git_data_getter = GitDataGetter(Fzf(), CommandRunner())
        add_preview = AddPreview(git_data_getter)
        colorized = add_preview.preview(file_path)
        remove(file_path)
        self.assertEqual(colorized,
                         'print(\x1b[33m"Hello Test"\x1b[39;49;00m)\n')
    def test_get_current_branch_name(self):
        branch = 'foo'
        command_runner = CommandRunner()
        command_runner.check_output = MagicMock(return_value=branch)

        git_data_getter = GitDataGetter(Fzf(), command_runner)
        result = git_data_getter.get_current_branch_name()

        self.assertEqual(result, 'foo')
        command_runner.check_output.assert_called_once_with(
            ['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
Exemplo n.º 7
0
    def test_run(self):
        stash = 'foo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_stash_ref = MagicMock(return_value=stash)

        hist_command_runer = HistoryCommandRunner(git_data_getter, command_runner)
        hist_command_runer.run = MagicMock()
        stash_pop = StashPop(hist_command_runer, git_data_getter)
        stash_pop.run()

        hist_command_runer.run.assert_called_once_with(['git', 'stash', 'pop', stash])
Exemplo n.º 8
0
    def test_run(self):
        hash = 'foo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_commit_hash = MagicMock(return_value=hash)

        hist_command_runer = HistoryCommandRunner(git_data_getter, command_runner)
        hist_command_runer.run_foreground = MagicMock()
        diff_commits = DiffCommits(hist_command_runer, git_data_getter)
        diff_commits.run()

        hist_command_runer.run_foreground.assert_called_once_with(['git', 'diff', hash, hash])
Exemplo n.º 9
0
    def test_run(self):
        branch = 'foo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_branch_name = MagicMock(return_value=branch)

        hist_command_runer = HistoryCommandRunner(git_data_getter, command_runner)
        hist_command_runer.run = MagicMock()
        merge_branch = MergeSquash(hist_command_runer, git_data_getter)
        merge_branch.run()

        hist_command_runer.run.assert_called_once_with(['git', 'merge', '--squash', branch])
Exemplo n.º 10
0
    def test_run(self):
        hash = 'foo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_commit_hash = MagicMock(return_value=hash)

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock()
        reset = Reset(hist_command_runer, git_data_getter)
        reset.run()

        hist_command_runer.run.assert_called_once_with(['git', 'reset', hash])
Exemplo n.º 11
0
    def test_run(self):
        tag = 'foo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_tag_name = MagicMock(return_value=tag)

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock()
        merge_tag = MergeTag(hist_command_runer, git_data_getter)
        merge_tag.run()

        hist_command_runer.run.assert_called_once_with(['git', 'merge', tag])
    def test_run(self):
        remote = 'bar'
        branch = 'foo'
        branches = [branch]
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_remote_name= MagicMock(return_value=remote)
        git_data_getter.get_branch_names_remote = MagicMock(return_value=branches)
        command_runner.run = MagicMock()
        delete_branch = DeleteBranchRemote(command_runner, git_data_getter)
        delete_branch.run()

        command_runner.run.assert_called_once_with(['git', 'push', remote, '--delete', branch])
Exemplo n.º 13
0
    def test_run(self):
        branch = 'foo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_branch_name = MagicMock(return_value=branch)

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock()
        checkout_branch = CheckoutBranch(hist_command_runer, git_data_getter)
        checkout_branch.run()

        hist_command_runer.run.assert_called_once_with(
            ['git', 'checkout', branch])
Exemplo n.º 14
0
    def test_run(self):
        remote = 'foo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_remote_name = MagicMock(return_value=remote)

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock()
        fetch = Fetch(hist_command_runer, git_data_getter)
        fetch.run()

        hist_command_runer.run.assert_called_once_with(
            ['git', 'fetch', remote])
Exemplo n.º 15
0
    def test_run(self):
        from_tag = 'v1.0.0'
        new_branch_name = 'newfoo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_tag_name = MagicMock(return_value=from_tag)
        git_data_getter.get_branch_name_from_input = MagicMock(return_value=new_branch_name)

        hist_command_runer = HistoryCommandRunner(git_data_getter, command_runner)
        hist_command_runer.run = MagicMock()
        branch_branch = BranchTag(hist_command_runer, git_data_getter)
        branch_branch.run()

        hist_command_runer.run.assert_called_once_with(['git', 'checkout', '-b', new_branch_name, from_tag])
Exemplo n.º 16
0
    def test_force_delete_no(self):
        branch = 'foo'
        branches = [branch]
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_branch_names = MagicMock(return_value=branches)
        git_data_getter.get_confirm_force_delete = MagicMock(return_value="n")

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock(
            return_value="error: not fully merged")
        delete_branch = DeleteBranch(hist_command_runer, git_data_getter)
        delete_branch.run()
Exemplo n.º 17
0
    def test_run(self):
        message = 'foo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_stash_message_from_input = MagicMock(
            return_value=message)

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock()
        stash_message = StashMessage(hist_command_runer, git_data_getter)
        stash_message.run()

        hist_command_runer.run.assert_called_once_with(
            ['git', 'stash', 'push', '-m', message])
Exemplo n.º 18
0
    def test_run(self):
        branch = 'foo'
        branches = [branch]
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_branch_names = MagicMock(return_value=branches)

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock()
        delete_branch = DeleteBranch(hist_command_runer, git_data_getter)
        delete_branch.run()

        hist_command_runer.run.assert_called_once_with(
            ['git', 'branch', '-d', branch])
Exemplo n.º 19
0
    def test_run(self):
        tag = 'foo'
        tags = [tag]
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_tag_names = MagicMock(return_value=tags)

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock()
        delete_tag = DeleteTag(hist_command_runer, git_data_getter)
        delete_tag.run()

        hist_command_runer.run.assert_called_once_with(
            ['git', 'tag', '-d', tag])
Exemplo n.º 20
0
    def test_run(self):
        remote = 'foo'
        tag = 'refs/tags/v1.0.0'
        tags = [tag]
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_remote_name = MagicMock(return_value=remote)
        git_data_getter.get_tag_names_remote = MagicMock(return_value=tags)

        hist_command_runer = HistoryCommandRunner(git_data_getter, command_runner)
        hist_command_runer.run = MagicMock()
        delete_tag_remote = DeleteTagRemote(hist_command_runer, git_data_getter)
        delete_tag_remote.run()

        calls = [call(['git', 'tag', '-d', tag]), call(['git', 'push', '--delete', remote, tag])]
        hist_command_runer.run.assert_has_calls(calls)
Exemplo n.º 21
0
    def test_run(self):
        tag = 'v1.0.0'
        remote = 'foo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_local_tag_name = MagicMock(return_value=tag)
        git_data_getter.get_remote_name = MagicMock(return_value=remote)

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock()
        fetch = PushTag(hist_command_runer, git_data_getter)
        fetch.run()

        hist_command_runer.run.assert_called_once_with(
            ['git', 'push', '-u', remote, tag])
Exemplo n.º 22
0
    def test_run(self):
        branch = 'foo'
        hash = 'bash'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_branch_name = MagicMock(return_value=branch)
        git_data_getter.get_commit_hash = MagicMock(return_value=hash)

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock()
        cherry_pick = CherryPick(hist_command_runer, git_data_getter)
        cherry_pick.run()

        hist_command_runer.run.assert_called_once_with(
            ['git', 'cherry-pick', '-e', hash])
Exemplo n.º 23
0
    def test_run(self):
        branch = 'bar'
        remote = 'foo'
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_current_branch_name = MagicMock(
            return_value=branch)
        git_data_getter.get_remote_name = MagicMock(return_value=remote)

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock()
        fetch = UpstreamPush(hist_command_runer, git_data_getter)
        fetch.run()

        hist_command_runer.run.assert_called_once_with(
            ['git', 'push', '-u', remote, branch])
Exemplo n.º 24
0
    def test_force_delete_yes(self):
        branch = 'foo'
        branches = [branch]
        command_runner = CommandRunner()
        git_data_getter = GitDataGetter(Fzf(), command_runner)
        git_data_getter.get_branch_names = MagicMock(return_value=branches)
        git_data_getter.get_confirm_force_delete = MagicMock(return_value="y")

        hist_command_runer = HistoryCommandRunner(git_data_getter,
                                                  command_runner)
        hist_command_runer.run = MagicMock(
            return_value="error: not fully merged")
        delete_branch = DeleteBranch(hist_command_runer, git_data_getter)
        delete_branch.run()

        calls = [
            call(['git', 'branch', '-d', branch]),
            call(['git', 'branch', '-D', branch])
        ]
        hist_command_runer.run.assert_has_calls(calls)
Exemplo n.º 25
0
def checkout_branch_remote_preview():
    git_data_getter = GitDataGetter(Fzf(), CommandRunner())
    cmd = git_data_getter.checkout_branch_remote_command(argv[1])
    print(' '.join(cmd))
Exemplo n.º 26
0
def add_preview():
    add_preview = AddPreview(GitDataGetter(Fzf(), CommandRunner()))
    print(add_preview.preview(argv[1]))
Exemplo n.º 27
0
 def __init__(self):
     command_runner = CommandRunner()
     self._fzf = Fzf()
     self._git_data_getter = GitDataGetter(self._fzf, command_runner)
     self._hist_command_runner = HistoryCommandRunner(
         self._git_data_getter, command_runner)