-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: respect .gitignore in Jujutsu (.jj) repositories #2016
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -696,9 +696,27 @@ pub fn scan(paths: &[PathBuf], patterns: Vec<Regex>, config: Config) -> Result<E | |
| WorkerState::new(patterns, config).scan(paths) | ||
| } | ||
|
|
||
| /// Whether the `ignore` crate should require a `.git` directory to apply gitignore rules. | ||
| /// | ||
| /// Jujutsu repositories use a `.jj` directory and still rely on `.gitignore` files. When a | ||
| /// search path is inside such a repository, treat it like `--no-require-git` unless the user | ||
| /// explicitly passes `--require-git`. | ||
| pub fn should_require_git_to_read_vcsignore( | ||
| search_paths: &[PathBuf], | ||
| no_require_git: bool, | ||
| ) -> bool { | ||
| if no_require_git { | ||
| return false; | ||
| } | ||
|
|
||
| !search_paths | ||
| .iter() | ||
| .any(|path| path.ancestors().any(|ancestor| ancestor.join(".jj").is_dir())) | ||
|
Comment on lines
+708
to
+714
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This helper cannot distinguish “default behavior” from an explicit Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::search_str_for_entry; | ||
| use super::{search_str_for_entry, should_require_git_to_read_vcsignore}; | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
| #[test] | ||
|
|
@@ -735,4 +753,17 @@ mod tests { | |
| PathBuf::from("bar") | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn should_require_git_in_jujutsu_repo() { | ||
| let temp = tempfile::tempdir().unwrap(); | ||
| let root = temp.path(); | ||
| std::fs::create_dir(root.join(".jj")).unwrap(); | ||
|
|
||
| assert!(!should_require_git_to_read_vcsignore( | ||
| &[root.join("src")], | ||
| false | ||
| )); | ||
| assert!(!should_require_git_to_read_vcsignore(&[root.join("src")], true)); | ||
| } | ||
| } | ||
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.
.jjpath.ancestors()only walks lexical components of the provided search path, so for the common default./(or other relative paths) it never reaches parent directories above the current working directory. That means runningfdfrom a subdirectory inside a Jujutsu repo (where.jjis at the repo root) will not be detected here, and.gitignorerules still won’t apply unless the user is at the root or passes an absolute path, which defeats the new feature for many real invocations.Useful? React with 👍 / 👎.