-
-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
What's nice is that it keeps track of the reference as well, which is a benefit. It will also do its best to not fail if the branch doesn't exist anymore but instead resorts to the id available in the reflog.
- Loading branch information
Showing
4 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
use crate::revision::spec::from_bytes::{parse_spec, repo}; | ||
|
||
#[test] | ||
#[ignore] | ||
fn nth_prior_checkout() { | ||
let repo = repo("complex_graph").unwrap(); | ||
|
||
for spec in ["@{-1}", "@{-2}", "@{-3}", "@{-4}", "@{-5}"] { | ||
assert!(parse_spec(spec, &repo).is_ok(), "spec {} should be valid", spec); | ||
for (spec, prior_branch) in [ | ||
("@{-1}", "refs/heads/i"), | ||
("@{-2}", "refs/heads/main"), | ||
("@{-3}", "refs/heads/e"), | ||
("@{-4}", "refs/heads/j"), | ||
("@{-5}", "refs/heads/h"), | ||
] { | ||
let parsed = parse_spec(spec, &repo).unwrap_or_else(|_| panic!("{} to be parsed successfully", spec)); | ||
assert_eq!(parsed.first_reference().expect("present").name.as_bstr(), prior_branch); | ||
} | ||
|
||
assert_eq!( | ||
parse_spec("@{-6}", &repo).unwrap_err().to_string(), | ||
"HEAD has 5 prior checkouts and checkout 6 is out of range" | ||
"HEAD has 5 prior checkouts and checkout number 6 is out of range" | ||
); | ||
} |