Repository navigation
feat(cli): sparse set warns on a prefix that matches nothing and refuses a bare set #197
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e311d4a
feat(cli): sparse set warns on a prefix that matches nothing and refu…
tonibergholm e747502
fix(cli): check unmatched sparse prefixes after the set; partial-clon…
tonibergholm 3447b8a
fix(repo): sparse set refuses a blank prefix; the unmatched check is …
tonibergholm b2e3fda
fix(repo): the unmatched-prefix lookup reads prefixes literally, like…
tonibergholm c40f066
fix(repo): refuse a blank clone filter and blank prefixes at the spar…
tonibergholm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| //! `sc sparse set` usability guards (P24 follow-ons): a prefix that matches | ||
| //! nothing is warned about, and a bare `sparse set` points at `sparse disable`. | ||
|
|
||
| use std::process::Command; | ||
|
|
||
| fn sc(dir: &std::path::Path, args: &[&str]) -> std::process::Output { | ||
| Command::new(env!("CARGO_BIN_EXE_sc")) | ||
| .args(args) | ||
| .current_dir(dir) | ||
| .output() | ||
| .expect("sc runs") | ||
| } | ||
|
|
||
| fn stderr(out: &std::process::Output) -> String { | ||
| String::from_utf8_lossy(&out.stderr).into_owned() | ||
| } | ||
|
|
||
| fn repo(tag: &str) -> std::path::PathBuf { | ||
| let root = | ||
| std::env::temp_dir().join(format!("scl-cli-sparse-ergo-{tag}-{}", std::process::id())); | ||
| let _ = std::fs::remove_dir_all(&root); | ||
| std::fs::create_dir_all(root.join("src")).unwrap(); | ||
| std::fs::create_dir_all(root.join("docs")).unwrap(); | ||
| assert!(sc(&root, &["init"]).status.success()); | ||
| std::fs::write(root.join("src/a.txt"), "a\n").unwrap(); | ||
| std::fs::write(root.join("docs/b.txt"), "b\n").unwrap(); | ||
| assert!(sc(&root, &["commit", "-m", "c1"]).status.success()); | ||
| root | ||
| } | ||
|
|
||
| /// A prefix naming nothing empties the tree; the command still succeeds, but | ||
| /// says so, and names the way back. | ||
| #[test] | ||
| fn a_prefix_matching_no_tracked_path_is_warned_about() { | ||
| let root = repo("nomatch"); | ||
| let out = sc(&root, &["sparse", "set", "sorc/"]); | ||
| assert!(out.status.success(), "{}", stderr(&out)); | ||
| let err = stderr(&out); | ||
| assert!(err.contains("matches no tracked path"), "{err}"); | ||
| assert!(err.contains("sc sparse disable"), "{err}"); | ||
| assert!(!root.join("src/a.txt").exists(), "the view really is empty"); | ||
|
|
||
| // A real prefix draws no warning, and a mixed set warns only for the miss. | ||
| assert!(sc(&root, &["sparse", "disable"]).status.success()); | ||
| let ok = sc(&root, &["sparse", "set", "src/"]); | ||
| assert!(ok.status.success()); | ||
| assert!( | ||
| !stderr(&ok).contains("matches no tracked path"), | ||
| "{}", | ||
| stderr(&ok) | ||
| ); | ||
| let mixed = sc(&root, &["sparse", "set", "src/", "nope/"]); | ||
| assert!(mixed.status.success()); | ||
| let err = stderr(&mixed); | ||
| assert!(err.contains("\"nope/\""), "{err}"); | ||
| assert!(!err.contains("\"src/\""), "{err}"); | ||
| std::fs::remove_dir_all(&root).unwrap(); | ||
| assert!(!root.exists()); | ||
| } | ||
|
|
||
| /// With no prefix `sparse set` was a silent `sparse disable`; it now refuses | ||
| /// and says which command means that. | ||
| #[test] | ||
| fn a_bare_sparse_set_points_at_disable() { | ||
| let root = repo("bare"); | ||
| assert!(sc(&root, &["sparse", "set", "src/"]).status.success()); | ||
| let out = sc(&root, &["sparse", "set"]); | ||
| assert!(!out.status.success(), "a bare `sparse set` must be refused"); | ||
| let err = stderr(&out); | ||
| assert!(err.contains("sc sparse disable"), "{err}"); | ||
| assert!(!root.join("docs/b.txt").exists(), "nothing was re-laid"); | ||
| std::fs::remove_dir_all(&root).unwrap(); | ||
| assert!(!root.exists()); | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.