Skip to content

Commit fc0529e

Browse files
committed
feat: checkout() now creates empty directories for submodules.
1 parent 73c685a commit fc0529e

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

gix-worktree-state/tests/fixtures/generated-archives/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
make_ignore_and_attributes_setup.tar.xz
22
make_mixed_without_submodules.tar.xz
3+
make_mixed.tar.xz
34
make_mixed_without_submodules_and_symlinks.tar.xz
45
make_attributes_baseline.tar.xz
56
make_dangerous_symlink.tar.xz
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
git init -q
5+
6+
touch empty
7+
echo -n "content" > executable
8+
chmod +x executable
9+
10+
mkdir dir
11+
echo "other content" > dir/content
12+
echo "* filter=arrow" > .gitattributes
13+
echo "executable -filter" >> .gitattributes
14+
echo ".gitattributes -filter" >> .gitattributes
15+
16+
mkdir dir/sub-dir
17+
(cd dir/sub-dir && ln -sf ../content symlink)
18+
19+
git add -A
20+
git commit -m "Commit"
21+
22+
git init module1
23+
(cd module1
24+
echo hello-from-submodule > f1
25+
mkdir dir
26+
: >dir/f2
27+
28+
git add . && git commit -m "init submodule"
29+
)
30+
31+
git submodule add ./module1 m1
32+
git submodule add ./module1 modules/m1

gix-worktree-state/tests/state/checkout.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ fn driver_exe() -> String {
4343
exe
4444
}
4545

46+
#[test]
47+
fn submodules_are_instantiated_as_directories() -> crate::Result {
48+
let mut opts = opts_from_probe();
49+
opts.overwrite_existing = false;
50+
let (_source_tree, destination, _index, _outcome) = checkout_index_in_tmp_dir(opts.clone(), "make_mixed")?;
51+
52+
for path in ["m1", "modules/m1"] {
53+
let sm = destination.path().join(path);
54+
assert!(sm.is_dir());
55+
assure_is_empty(sm)?;
56+
}
57+
58+
Ok(())
59+
}
60+
61+
fn assure_is_empty(dir: impl AsRef<Path>) -> std::io::Result<()> {
62+
assert_eq!(std::fs::read_dir(dir)?.count(), 0);
63+
Ok(())
64+
}
65+
4666
#[test]
4767
fn accidental_writes_through_symlinks_are_prevented_if_overwriting_is_forbidden() {
4868
let mut opts = opts_from_probe();
@@ -106,7 +126,7 @@ fn writes_through_symlinks_are_prevented_even_if_overwriting_is_allowed() {
106126
if cfg!(windows) { "A-dir\\a" } else { "A-dir/a" },
107127
"A-file",
108128
"FAKE-DIR",
109-
"FAKE-FILE"
129+
if cfg!(windows) { "fake-file" } else { "FAKE-FILE" }
110130
]),
111131
);
112132
assert!(outcome.collisions.is_empty());
@@ -165,7 +185,7 @@ fn overwriting_files_and_lone_directories_works() -> crate::Result {
165185
setup_filter_pipeline(opts.filters.options_mut());
166186
let (source, destination, _index, outcome) = checkout_index_in_tmp_dir_opts(
167187
opts.clone(),
168-
"make_mixed_without_submodules",
188+
"make_mixed",
169189
|_| true,
170190
|d| {
171191
let empty = d.join("empty");

0 commit comments

Comments
 (0)