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

Optional command-line keyword arguments #192

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions nbgitpuller/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,14 @@ def main():
parser = argparse.ArgumentParser(description='Synchronizes a github repository with a local repository.')
parser.add_argument('git_url', help='Url of the repo to sync')
parser.add_argument('branch_name', default=None, help='Branch of repo to sync', nargs='?')
parser.add_argument('repo_dir', default='.', help='Path to clone repo under', nargs='?')
parser.add_argument('--target-dir', default='.', help='Path to clone repo under')

args = parser.parse_args()

for line in GitPuller(
args.git_url,
args.repo_dir,
branch=args.branch_name if args.branch_name else None
args.target_dir,
branch=args.branch_name
).pull():
print(line)

Expand Down
11 changes: 8 additions & 3 deletions tests/test_gitpuller.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ def test_initialize():
def command_line_test_helper(remote_path, branch, pusher_path):
work_dir = "/".join(os.path.dirname(os.path.abspath(__file__)).split("/")[:-1]) + "/nbgitpuller"
try:
cmd = ['python3', 'pull.py', remote_path, branch, pusher_path]
cmd = ['python3', 'pull.py', remote_path]
if branch is not None:
cmd += [branch]
if pusher_path is not None:
cmd += ['--target-dir', pusher_path]
sp.check_output(
cmd,
cwd=work_dir
Expand All @@ -119,8 +123,9 @@ def test_command_line_existing_branch():
assert subprocess_result


def test_command_line_default_branch():
branch = ""
def test_command_line_no_branch_passed():
# so it should use the default branch
branch = None
with Remote() as remote, Pusher(remote) as pusher:
pusher.push_file('README.md', '1')
remotepath = "file://%s" % os.path.abspath(remote.path)
Expand Down