Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement --no-fetch option #46

Merged
merged 1 commit into from
Feb 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions PyGitUp/gitup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
git up -- like 'git pull', but polite

Usage: git up [-h | --version | --quiet]
Usage: git up [-h | --version | --quiet | --no-fetch | --no-f]

Options:
-h Show this screen.
Expand Down Expand Up @@ -136,6 +136,7 @@ def __init__(self, testing=False, sparse=False):
self.stderr = sys.stderr

self.states = []
self.should_fetch = True

# Check, if we're in a git repo
try:
Expand Down Expand Up @@ -206,7 +207,8 @@ def __init__(self, testing=False, sparse=False):
def run(self):
""" Run all the git-up stuff. """
try:
self.fetch()
if self.should_fetch:
self.fetch()

with self.git.stash():
with self.returning_to_current_branch():
Expand Down Expand Up @@ -595,6 +597,9 @@ def run(): # pragma: no cover

try:
gitup = GitUp()

if arguments['--no-fetch'] or arguments['--no-f']:
gitup.should_fetch = False
except GitError:
sys.exit(1) # Error in constructor
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def write_file(path, contents):


#noinspection PyDefaultArgument
def update_file(repo, commit_message='', counter=[0]):
def update_file(repo, commit_message='', testfile_name=testfile_name, counter=[0]):
"""
Update 'testfile_name' using an increasing counter and commit the changes.
"""
Expand Down
70 changes: 70 additions & 0 deletions tests/test_nofetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# System imports
import os
from os.path import join

# 3rd party libs
from nose.tools import *
from git import *

# PyGitup imports
from tests import basepath, capture, update_file, init_master

test_name = 'no-fetch'
new_branch_name = test_name + '.2'
another_file_name = 'another_file.txt'

origin_test_name = 'origin/' + test_name

repo_path = join(basepath, test_name + os.sep)


def setup():
master_path, master = init_master(test_name)

# Prepare master repo
master.git.checkout(b=test_name)

# Clone to test repo
path = join(basepath, test_name)
master.clone(path, b=test_name)

repo = Repo(path, odbt=GitCmdObjectDB)

assert repo.working_dir == path

# Create new local branch and set upstream
repo.git.checkout(b=new_branch_name)
repo.git.branch(u=origin_test_name)

# Make non-conflicting change in new branch
update_file(repo, new_branch_name, testfile_name=another_file_name)

# Modify file in master
update_file(master, test_name)

# Update first branch
repo.git.checkout(test_name)
repo.git.pull()



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)