feat(switch): accept revset arguments, and explicitly support -
shorthand
#1463
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This updated
git switch
to accept a revset as it's argument, and also to support-
(to checkout previously checked out branch/commit) by passing it through to git.The revset parameter must evaluate to a set with a single head, and I've found this handy in cases like
current(...)
to move to the latest version of a commit if I had an old smartlog or SHA still on screen or such, and alsoswitch foo:
for when I have a branch ref handy but I really want to checkout the latest detached commit in that stack.But with revset support added,
switch -
broke because it looked a poorly formed revset:The last commit in this stack adds an explicit check for
-
so that this support is restored.Apparently,
revparse_single()
inlibgit2
doesn't support this. ~~I didn't patch-
support intorepo.revparse_single_commit()
but I'm thinking as I write this that perhaps that may be better? There is already a special case in that function to work around anotherlibgit2
issue, and I suppose we could detect if the passed spec is-
and then pass@{-1}
torevparse_single()
instead. 🤔 ~~ edit I made this change and it seems to be working.