History

Make .gitignore name overridable (#301)

This is the only override that is allowed, .gitattributes isn't allowed for instance. Don't know what it is used for, but `git ls-files` can set this with a flag.

Sebastian Thiel committed 4 years ago

Commit 155bb821 parent dec9f332 files · +15 −1Browse files

Unified · Split

2 files
  1. git-worktree/src/fs/cache.rs +14 −1
  2. git-worktree/tests/worktree/fs/cache.rs +1 −0
git-worktree/src/fs/cache.rs+14−1
@@ -28,6 +28,7 @@ pub enum State { · 27 unmodified lines
2828
2929 ///
3030 pub mod state {
31+ use bstr::{BStr, BString};
3132 use std::path::Path;
3233
3334 type AttributeMatchGroup = git_attributes::MatchGroup<git_attributes::Attributes>;
@@ -54,14 +55,26 @@ pub mod state { · 20 unmodified lines
5455 pub stack: IgnoreMatchGroup,
5556 /// Ignore patterns which aren't tied to the repository root, hence are global. They are consulted last.
5657 pub globals: IgnoreMatchGroup,
58+ /// The name of the file to look for in directories.
59+ pub exclude_file_name_for_directories: BString,
5760 }
5861
5962 impl Ignore {
60− pub fn new(overrides: IgnoreMatchGroup, globals: IgnoreMatchGroup) -> Self {
63+ /// The `exclude_file_name_for_directories` is an optional override for the filename to use when checking per-directory
64+ /// ignore files within the repository, defaults to`.gitignore`.
65+ // TODO: more docs
66+ pub fn new(
67+ overrides: IgnoreMatchGroup,
68+ globals: IgnoreMatchGroup,
69+ exclude_file_name_for_directories: Option<&BStr>,
70+ ) -> Self {
6171 Ignore {
6272 overrides,
6373 globals,
6474 stack: Default::default(),
75+ exclude_file_name_for_directories: exclude_file_name_for_directories
76+ .map(ToOwned::to_owned)
77+ .unwrap_or(".gitignore".into()),
6578 }
6679 }
6780
git-worktree/tests/worktree/fs/cache.rs+1−0
@@ -149,6 +149,7 @@ mod ignore_and_attributes { · 148 unmodified lines
149149 git_worktree::fs::cache::state::Ignore::new(
150150 git_attributes::MatchGroup::from_overrides(vec!["!force-include"]),
151151 git_attributes::MatchGroup::from_git_dir(&git_dir, Some(user_exclude_path), &mut buf).unwrap(),
152+ None,
152153 ),
153154 ),
154155 Default::default(),