History

Merge pull request #2029 from GitoxideLabs/submodule-all

Add a test to assure `subomdule.<name>.ignore = all` is handled correctly.

Sebastian Thiel committed 1 year ago

Commit b199c6e2 parents 5546baa 657dec43 files · +149 −18Browse files

Unified · Split

3 files
  1. gix/tests/fixtures/generated-archives/make_submodules.tar +0 −0
  2. gix/tests/fixtures/make_submodules.sh +6 −0
  3. gix/tests/gix/status.rs +144 −19
gix/tests/fixtures/generated-archives/make_submodules.tar+0−0

Binary file not shown.

gix/tests/fixtures/make_submodules.sh+6−0
@@ -85,6 +85,12 @@ cp -Rv modified-untracked-and-submodule-head-changed-and-modified git-mv-and-unt · 84 unmodified lines
8585 git mv this that
8686 )
8787
88+cp -Rv git-mv-and-untracked-and-submodule-head-changed-and-modified git-mv-and-untracked-and-submodule-head-changed-and-modified-ignore-all
89+(cd git-mv-and-untracked-and-submodule-head-changed-and-modified-ignore-all
90+ echo $'\tignore = all' >>.gitmodules
91+ git add .gitmodules && git commit -m "ignore all submodule changes"
92+)
93+
8894 git init with-submodules
8995 (cd with-submodules
9096 mkdir dir
gix/tests/gix/status.rs+144−19
@@ -17,7 +17,7 @@ pub fn repo(name: &str) -> crate::Result<gix::Repository> { · 16 unmodified lines
1717 }
1818
1919 mod into_iter {
20− use gix::status::{tree_index::TrackRenames, Item};
20+ use gix::status::{tree_index::TrackRenames, Item, Submodule};
2121 use gix_diff::Rewrites;
2222 use gix_testtools::size_ok;
2323
@@ -53,24 +53,149 @@ mod into_iter { · 29 unmodified lines
5353 let mut items: Vec<_> = status.by_ref().filter_map(Result::ok).collect();
5454 items.sort_by(|a, b| a.location().cmp(b.location()));
5555 assert_eq!(items.len(), 3, "1 untracked, 1 move, 1 submodule modification");
56− insta::assert_debug_snapshot!(&items[1], @r#"
57− TreeIndex(
58− Rewrite {
59− source_location: "this",
60− source_index: 2,
61− source_entry_mode: Mode(
62− FILE,
63− ),
64− source_id: Sha1(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391),
65− location: "that",
66− index: 2,
67− entry_mode: Mode(
68− FILE,
69− ),
70− id: Sha1(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391),
71− copy: false,
72− },
73− )
56+ insta::assert_debug_snapshot!(&items[1..], @r#"
57+ [
58+ TreeIndex(
59+ Rewrite {
60+ source_location: "this",
61+ source_index: 2,
62+ source_entry_mode: Mode(
63+ FILE,
64+ ),
65+ source_id: Sha1(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391),
66+ location: "that",
67+ index: 2,
68+ entry_mode: Mode(
69+ FILE,
70+ ),
71+ id: Sha1(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391),
72+ copy: false,
73+ },
74+ ),
75+ IndexWorktree(
76+ DirectoryContents {
77+ entry: Entry {
78+ rela_path: "untracked",
79+ status: Untracked,
80+ property: None,
81+ disk_kind: Some(
82+ File,
83+ ),
84+ index_kind: None,
85+ pathspec_match: Some(
86+ Always,
87+ ),
88+ },
89+ collapsed_directory_status: None,
90+ },
91+ ),
92+ ]
93+ "#);
94+ Ok(())
95+ }
96+
97+ #[test]
98+ fn submodule_fully_ignored_by_override() -> crate::Result {
99+ let repo = submodule_repo("git-mv-and-untracked-and-submodule-head-changed-and-modified")?;
100+ let mut status = repo
101+ .status(gix::progress::Discard)?
102+ .index_worktree_options_mut(|opts| {
103+ opts.sorting =
104+ Some(gix::status::plumbing::index_as_worktree_with_renames::Sorting::ByPathCaseSensitive);
105+ })
106+ .tree_index_track_renames(TrackRenames::Given(Rewrites {
107+ track_empty: true,
108+ ..Default::default()
109+ }))
110+ .index_worktree_submodules(Some(Submodule::Given {
111+ ignore: gix::submodule::config::Ignore::All,
112+ check_dirty: false,
113+ }))
114+ .into_iter(None)?;
115+ let mut items: Vec<_> = status.by_ref().filter_map(Result::ok).collect();
116+ items.sort_by(|a, b| a.location().cmp(b.location()));
117+ assert_eq!(
118+ items.len(),
119+ 2,
120+ "1 untracked, 1 move, 0 submodule modification (ignored)"
121+ );
122+ insta::assert_debug_snapshot!(&items, @r#"
123+ [
124+ TreeIndex(
125+ Rewrite {
126+ source_location: "this",
127+ source_index: 2,
128+ source_entry_mode: Mode(
129+ FILE,
130+ ),
131+ source_id: Sha1(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391),
132+ location: "that",
133+ index: 2,
134+ entry_mode: Mode(
135+ FILE,
136+ ),
137+ id: Sha1(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391),
138+ copy: false,
139+ },
140+ ),
141+ IndexWorktree(
142+ DirectoryContents {
143+ entry: Entry {
144+ rela_path: "untracked",
145+ status: Untracked,
146+ property: None,
147+ disk_kind: Some(
148+ File,
149+ ),
150+ index_kind: None,
151+ pathspec_match: Some(
152+ Always,
153+ ),
154+ },
155+ collapsed_directory_status: None,
156+ },
157+ ),
158+ ]
159+ "#);
160+ Ok(())
161+ }
162+ #[test]
163+ fn submodule_fully_ignored_by_configuration() -> crate::Result {
164+ let repo = submodule_repo("git-mv-and-untracked-and-submodule-head-changed-and-modified-ignore-all")?;
165+ let mut status = repo
166+ .status(gix::progress::Discard)?
167+ .index_worktree_options_mut(|opts| {
168+ opts.sorting =
169+ Some(gix::status::plumbing::index_as_worktree_with_renames::Sorting::ByPathCaseSensitive);
170+ })
171+ .tree_index_track_renames(TrackRenames::Given(Rewrites {
172+ track_empty: true,
173+ ..Default::default()
174+ }))
175+ .into_iter(None)?;
176+ let mut items: Vec<_> = status.by_ref().filter_map(Result::ok).collect();
177+ items.sort_by(|a, b| a.location().cmp(b.location()));
178+ assert_eq!(items.len(), 1, "1 untracked, 0 submodule modification (ignored)");
179+ insta::assert_debug_snapshot!(&items, @r#"
180+ [
181+ IndexWorktree(
182+ DirectoryContents {
183+ entry: Entry {
184+ rela_path: "untracked",
185+ status: Untracked,
186+ property: None,
187+ disk_kind: Some(
188+ File,
189+ ),
190+ index_kind: None,
191+ pathspec_match: Some(
192+ Always,
193+ ),
194+ },
195+ collapsed_directory_status: None,
196+ },
197+ ),
198+ ]
74199 "#);
75200 Ok(())
76201 }