Skip to content

Commit

Permalink
Add flag repo to specify repository name on first switch (#50)
Browse files Browse the repository at this point in the history
* Add flag to specify repo name

* improvements

* update changelog
  • Loading branch information
sshane authored Apr 11, 2021
1 parent a065118 commit 922422f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Release 0.1.15 (2021-04-11)
=====

* Add `repo` flag to `emu fork switch` command: if a repository's name isn't openpilot and isn't a GitHub fork (no name redirection), you can use this option the first time you switch to the fork (remembers URL after that).


Release 0.1.14 (2021-04-02)
=====

Expand Down
9 changes: 7 additions & 2 deletions commands/fork/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
REMOTE_BRANCHES_START = 'Remote branches:\n'
REMOTE_BRANCH_START = 'Remote branch:'
CLONING_PATH = '{}/.cloning'.format(OH_MY_COMMA_PATH)
DEFAULT_REPO_NAME = 'openpilot'


def set_cloning(cloning):
Expand Down Expand Up @@ -104,6 +105,7 @@ def __init__(self):
self.commands = {'switch': Command(description='🍴 Switch between any openpilot fork',
flags=[Flag('username', '👤 The username of the fork\'s owner to switch to, will use current fork if not provided', required=False, dtype='str'),
Flag(['-b', '--branch'], '🌿 Branch to switch to, will use default branch if not provided', required=False, dtype='str'),
Flag(['-r', '--repo'], 'The repository name of the fork, if its name isn\'t openpilot', required=False, dtype='str'),
Flag(['-f', '--force'], '💪 Similar to checkout -f, force checks out new branch overwriting any changes')]),
'list': Command(description='📜 See a list of installed forks and branches',
flags=[Flag('fork', '🌿 See branches of specified fork', dtype='str')])}
Expand Down Expand Up @@ -168,6 +170,7 @@ def _switch(self):

username = flags.username
branch = flags.branch
repo_name = flags.repo
force_switch = flags.force
if username is None: # branch is specified, so use current checked out fork/username
_current_fork = self.fork_params.get('current_fork')
Expand All @@ -190,10 +193,12 @@ def _switch(self):
if remote_info is not None:
remote_url = f'https://github.com/{username}/{remote_info.fork_name}' # dragonpilot doesn't have a GH redirect
else: # for most forks, GH will redirect from /openpilot if user renames fork
remote_url = f'https://github.com/{username}/openpilot'
if repo_name is None:
repo_name = DEFAULT_REPO_NAME # openpilot
remote_url = f'https://github.com/{username}/{repo_name}'

if not valid_fork_url(remote_url):
error('Invalid username! {} does not exist'.format(remote_url))
error('Invalid username{}! {} does not exist'.format('' if flags.repo is None else ' or repository name', remote_url))
return

r = check_output(['git', '-C', OPENPILOT_PATH, 'remote', 'add', username, remote_url])
Expand Down

0 comments on commit 922422f

Please sign in to comment.