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

Allow sno switch to switch to new local branch tracking remote branch #292

Merged
merged 1 commit into from
Oct 29, 2020

Conversation

olsen232
Copy link
Collaborator

Description

sno switch x switches to x if x is a local branch - as before.
sno switch origin/x fails as before: you cannot switch to a remote branch
But, sno switch x where x is not yet a local branch but is the name of a remote branch, creates a local branch x that tracks origin/x. (Just as it does in git)

sno checkout behave similarly, but note that with sno checkout, you CAN sno checkout origin/x - this refish is resolved to a particular commit, and that commit is checked out as a "detached HEAD".

Related links:

Fixes #259

Checklist:

  • Have you reviewed your own change?
  • Have you included test(s)?
  • Have you updated the changelog?

@olsen232 olsen232 requested review from craigds and rcoup October 29, 2020 02:06
sno/checkout.py Outdated
@@ -178,27 +208,65 @@ def switch(ctx, create, force_create, discard_changes, refish):
# Switch to existing branch
#
# refish could be:
# - branch name
# - local branch name eg 'master'
# - remote branch name eg 'master' (if do_guess is True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# - remote branch name eg 'master' (if do_guess is True)
# - local branch name (eg 'master') that only exists on remote (if do_guess is True)

sno/checkout.py Outdated
head_ref = branch.name

reset_wc_if_needed(repo, commit, discard_changes=discard_changes)

repo.set_head(head_ref)


def _find_remote_by_name(repo, name):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest calling this _find_remote_branch_by_name, since it finds a branch rather than a remote

@olsen232 olsen232 merged commit be120af into master Oct 29, 2020
@olsen232 olsen232 deleted the sno_switch branch October 29, 2020 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sno switch [branch] doesn't switch to upstream branch if it exists
2 participants