-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
feat(switch): accept revset arguments, and explicitly support -
shorthand
#1463
base: master
Are you sure you want to change the base?
Conversation
5cc1b7a
to
df58ccf
Compare
df58ccf
to
72fab57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Both of these issues have bothered me personally as well.
@@ -512,16 +512,22 @@ pub fn switch( | |||
|
|||
enum Target { | |||
Interactive(String), | |||
Revision(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: I think it's misleading to call this Revision
, because it sounds like it's meant to refer to a revision/commit specifically, and not be a general revision specification, which can indicate a branch.
Some ideas for renaming it:
Revspec
(but I'm not sure if this is legitimate Git terminology)RevisionOrRef
RevparseSingleCommit
Uninterpreted
or similar- I guess it would be better if
CheckoutTarget::Unknown
were actually namedCheckoutTarget::Uninterpreted
or similar, sinceUnknown
is kind of weird to say when the value is clearly known.
- I guess it would be better if
Let's also add a comment to this enum
case explaining that it can also represent branches, etc.
|
||
match commits.as_slice() { | ||
[commit] => Some(CheckoutTarget::Unknown(commit.get_oid().to_string())), | ||
[] => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Is it intentional for you that having a revset that resolves to the empty set should do nothing? I could imagine it being useful for some workflow, although I don't have one in mind.
issue: Technically speaking, isn't the stated specification that the set must have exactly 1 head not correct?
[..] => { | ||
writeln!( | ||
effects.get_error_stream(), | ||
"Cannot switch to target: expected '{target}' to contain 1 head, but found {}.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment (non-blocking): In principle we could list all of the candidate targets, which we also do when git next
or git prev
is ambiguous, but it's not necessary to implement that here.
|
||
{ | ||
// switching back to "last checkout" | ||
let (stdout, _stderr) = git.branchless("switch", &["-"])?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Can you add a test to ensure that git switch -
is also capable of checking out the previous branch, not just the previous commit? (I believe that's how it works in Git.)
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.