Skip to content

Commit c847b77

Browse files
committed
Fix CI failures that happen due to docker-avoidance.
It's an interesting side-effect that running in Docker seems to work better, maybe due to running as root? Try to emulate what seems to be happening on CI by changing the desired umask, which usually does the right thing when running locally.
1 parent 5ccdd1a commit c847b77

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

crates/but-testsupport/src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,29 @@ pub fn visualize_tree(tree_id: gix::Id<'_>) -> termtree::Tree<String> {
154154
///
155155
/// # IMPORTANT: Portability
156156
///
157-
/// As it's intended for tests, this can't be called on Windows were modes don't exist.
158-
/// Further, be sure to set the `umask` of the process to something explicit, or else it may differ
159-
/// between runs and cause failures.
157+
/// * As it's intended for tests, this can't be called on Windows were modes don't exist.
158+
/// Further, be sure to set the `umask` of the process to something explicit, or else it may differ
159+
/// between runs and cause failures.
160+
/// * To avoid umask-specific errors across different systems, which may or may not use it for all operations,
161+
/// we 'normalize' umasks to what Git would track. This normalisation may need adjustments as different systems
162+
/// are encountered.
160163
#[cfg(unix)]
161164
pub fn visualize_disk_tree_skip_dot_git(root: &Path) -> anyhow::Result<termtree::Tree<String>> {
162165
use std::os::unix::fs::MetadataExt;
166+
fn normalize_mode(mode: u32) -> u32 {
167+
match mode {
168+
0o40777 => 0o40755,
169+
0o100666 => 0o100644,
170+
0o100777 => 0o100755,
171+
0o120777 => 0o120755,
172+
other => other,
173+
}
174+
}
163175
fn label(p: &Path, md: &std::fs::Metadata) -> String {
164176
format!(
165177
"{name}:{mode:o}",
166178
name = p.file_name().unwrap().to_str().unwrap(),
167-
mode = md.mode(),
179+
mode = normalize_mode(md.mode()),
168180
)
169181
}
170182

crates/but-workspace/tests/fixtures/scenario/one-commit-detached.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set -eu -o pipefail
66

77
git init
88
touch file && git add . && git commit -m "init"
9-
git checkout @
9+
git checkout --detach HEAD

crates/but-workspace/tests/workspace/discard.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ fn all_file_types_added_to_index() -> anyhow::Result<()> {
4040
#[test]
4141
#[cfg(unix)]
4242
fn all_file_types_deleted_in_worktree() -> anyhow::Result<()> {
43-
util::control_umask();
4443
let (repo, _tmp) = writable_scenario("delete-all-file-types-valid-submodule");
4544
insta::assert_snapshot!(git_status(&repo)?, @r"
4645
D .gitmodules
@@ -82,7 +81,6 @@ fn all_file_types_deleted_in_worktree() -> anyhow::Result<()> {
8281
#[test]
8382
#[cfg(unix)]
8483
fn replace_dir_with_file_discard_all_in_order_in_worktree() -> anyhow::Result<()> {
85-
util::control_umask();
8684
let (repo, _tmp) = writable_scenario("replace-dir-with-submodule-with-file");
8785
insta::assert_snapshot!(git_status(&repo)?, @r"
8886
D dir/executable
@@ -129,7 +127,6 @@ fn replace_dir_with_file_discard_all_in_order_in_worktree() -> anyhow::Result<()
129127
#[test]
130128
#[cfg(unix)]
131129
fn replace_dir_with_file_discard_all_in_order_in_index() -> anyhow::Result<()> {
132-
util::control_umask();
133130
let (repo, _tmp) = writable_scenario("replace-dir-with-submodule-with-file");
134131
git(&repo).args(["add", "."]).run();
135132
insta::assert_snapshot!(git_status(&repo)?, @r"
@@ -177,7 +174,6 @@ fn replace_dir_with_file_discard_all_in_order_in_index() -> anyhow::Result<()> {
177174
#[test]
178175
#[cfg(unix)]
179176
fn replace_dir_with_file_discard_just_the_file_in_worktree() -> anyhow::Result<()> {
180-
util::control_umask();
181177
let (repo, _tmp) = writable_scenario("replace-dir-with-submodule-with-file");
182178
insta::assert_snapshot!(git_status(&repo)?, @r"
183179
D dir/executable
@@ -220,7 +216,6 @@ fn replace_dir_with_file_discard_just_the_file_in_worktree() -> anyhow::Result<(
220216
#[test]
221217
#[cfg(unix)]
222218
fn conflicts_are_invisible() -> anyhow::Result<()> {
223-
util::control_umask();
224219
let (repo, _tmp) = writable_scenario("merge-with-two-branches-conflict");
225220
insta::assert_snapshot!(git_status(&repo)?, @"UU file");
226221
insta::assert_snapshot!(visualize_index(&**repo.index()?), @r"
@@ -254,7 +249,6 @@ fn conflicts_are_invisible() -> anyhow::Result<()> {
254249
#[test]
255250
#[cfg(unix)]
256251
fn replace_dir_with_file_discard_just_the_file_in_index() -> anyhow::Result<()> {
257-
util::control_umask();
258252
let (repo, _tmp) = writable_scenario("replace-dir-with-submodule-with-file");
259253
git(&repo).args(["add", "."]).run();
260254
insta::assert_snapshot!(git_status(&repo)?, @r"
@@ -298,7 +292,6 @@ fn replace_dir_with_file_discard_just_the_file_in_index() -> anyhow::Result<()>
298292
#[test]
299293
#[cfg(unix)]
300294
fn all_file_types_modified_in_worktree() -> anyhow::Result<()> {
301-
util::control_umask();
302295
let (repo, _tmp) = writable_scenario_slow("all-file-types-changed");
303296
insta::assert_snapshot!(git_status(&repo)?, @r"
304297
M soon-executable
@@ -338,7 +331,6 @@ fn all_file_types_modified_in_worktree() -> anyhow::Result<()> {
338331
#[test]
339332
#[cfg(unix)]
340333
fn all_file_types_modified_in_index() -> anyhow::Result<()> {
341-
util::control_umask();
342334
let (repo, _tmp) = writable_scenario_slow("all-file-types-changed");
343335
git(&repo).args(["add", "."]).run();
344336
insta::assert_snapshot!(git_status(&repo)?, @r"
@@ -379,7 +371,6 @@ fn all_file_types_modified_in_index() -> anyhow::Result<()> {
379371
#[test]
380372
#[cfg(unix)]
381373
fn modified_submodule_and_embedded_repo_in_worktree() -> anyhow::Result<()> {
382-
util::control_umask();
383374
let (repo, _tmp) = writable_scenario("modified-submodule-and-embedded-repo");
384375
insta::assert_snapshot!(git_status(&repo)?, @r"
385376
M embedded-repository
@@ -435,7 +426,6 @@ fn modified_submodule_and_embedded_repo_in_worktree() -> anyhow::Result<()> {
435426
#[test]
436427
#[cfg(unix)]
437428
fn modified_submodule_and_embedded_repo_in_index() -> anyhow::Result<()> {
438-
util::control_umask();
439429
let (repo, _tmp) = writable_scenario("modified-submodule-and-embedded-repo");
440430
git(&repo).args(["add", "."]).run();
441431
insta::assert_snapshot!(git_status(&repo)?, @r"
@@ -465,7 +455,6 @@ fn modified_submodule_and_embedded_repo_in_index() -> anyhow::Result<()> {
465455
#[test]
466456
#[cfg(unix)]
467457
fn all_file_types_renamed_and_modified_in_worktree() -> anyhow::Result<()> {
468-
util::control_umask();
469458
let (repo, _tmp) = writable_scenario_slow("all-file-types-renamed-and-modified");
470459
// Git doesn't detect renames between index/worktree, but we do.
471460
insta::assert_snapshot!(git_status(&repo)?, @r"
@@ -509,7 +498,6 @@ fn all_file_types_renamed_and_modified_in_worktree() -> anyhow::Result<()> {
509498
#[test]
510499
#[cfg(unix)]
511500
fn all_file_types_renamed_modified_in_index() -> anyhow::Result<()> {
512-
util::control_umask();
513501
let (repo, _tmp) = writable_scenario_slow("all-file-types-renamed-and-modified");
514502
git(&repo).args(["add", "."]).run();
515503
insta::assert_snapshot!(git_status(&repo)?, @r"
@@ -556,7 +544,6 @@ fn all_file_types_renamed_modified_in_index() -> anyhow::Result<()> {
556544
#[test]
557545
#[cfg(unix)]
558546
fn all_file_types_renamed_overwriting_existing_and_modified_in_worktree() -> anyhow::Result<()> {
559-
util::control_umask();
560547
let (repo, _tmp) = writable_scenario_slow("all-file-types-renamed-and-overwriting-existing");
561548
// This is actually misleading as `file-to-be-dir` seems missing even though it's now
562549
// a directory. It's untracked-state isn't visible.
@@ -623,7 +610,6 @@ fn all_file_types_renamed_overwriting_existing_and_modified_in_worktree() -> any
623610
#[test]
624611
#[cfg(unix)]
625612
fn all_file_types_renamed_overwriting_existing_and_modified_in_index() -> anyhow::Result<()> {
626-
util::control_umask();
627613
let (repo, _tmp) = writable_scenario_slow("all-file-types-renamed-and-overwriting-existing");
628614
git(&repo).args(["add", "."]).run();
629615
// This is actually misleading as `file-to-be-dir` seems missing even though it's now
@@ -693,7 +679,6 @@ fn all_file_types_renamed_overwriting_existing_and_modified_in_index() -> anyhow
693679
#[cfg(unix)]
694680
fn all_file_types_renamed_overwriting_existing_and_modified_in_worktree_discard_selectively()
695681
-> anyhow::Result<()> {
696-
util::control_umask();
697682
let (repo, _tmp) = writable_scenario_slow("all-file-types-renamed-and-overwriting-existing");
698683
// This is actually misleading as `file-to-be-dir` seems missing even though it's now
699684
// a directory. It's untracked-state isn't visible.
@@ -788,7 +773,6 @@ fn all_file_types_renamed_overwriting_existing_and_modified_in_worktree_discard_
788773
#[test]
789774
#[cfg(unix)]
790775
fn folder_with_all_file_types_moved_upwards_in_worktree() -> anyhow::Result<()> {
791-
util::control_umask();
792776
let (repo, _tmp) = writable_scenario_slow("move-directory-into-sibling-file");
793777
insta::assert_snapshot!(git_status(&repo)?, @r"
794778
D a/b/executable
@@ -839,7 +823,6 @@ fn folder_with_all_file_types_moved_upwards_in_worktree() -> anyhow::Result<()>
839823
#[test]
840824
#[cfg(unix)]
841825
fn folder_with_all_file_types_moved_upwards_in_worktree_discard_selected() -> anyhow::Result<()> {
842-
util::control_umask();
843826
let (repo, _tmp) = writable_scenario_slow("move-directory-into-sibling-file");
844827
insta::assert_snapshot!(git_status(&repo)?, @r"
845828
D a/b/executable
@@ -888,7 +871,6 @@ fn folder_with_all_file_types_moved_upwards_in_worktree_discard_selected() -> an
888871
#[test]
889872
#[cfg(unix)]
890873
fn folder_with_all_file_types_moved_upwards_in_index() -> anyhow::Result<()> {
891-
util::control_umask();
892874
let (repo, _tmp) = writable_scenario_slow("move-directory-into-sibling-file");
893875
git(&repo).args(["add", "."]).run();
894876
insta::assert_snapshot!(git_status(&repo)?, @r"
@@ -925,7 +907,6 @@ fn folder_with_all_file_types_moved_upwards_in_index() -> anyhow::Result<()> {
925907
#[test]
926908
#[cfg(unix)]
927909
fn all_file_types_deleted_in_index() -> anyhow::Result<()> {
928-
util::control_umask();
929910
let (repo, _tmp) = writable_scenario("delete-all-file-types-valid-submodule");
930911
insta::assert_snapshot!(git_status(&repo)?, @r"
931912
D .gitmodules
@@ -993,13 +974,6 @@ mod util {
993974
.into()
994975
}
995976

996-
/// Set the process umask to a known value so filesystem listings will be as we expect on all machines.
997-
#[cfg(unix)]
998-
pub fn control_umask() {
999-
use rustix::fs::Mode;
1000-
rustix::process::umask(Mode::from_bits(0o022).unwrap());
1001-
}
1002-
1003977
pub fn worktree_changes_to_discard_specs(
1004978
repo: &gix::Repository,
1005979
) -> impl Iterator<Item = DiscardSpec> {

0 commit comments

Comments
 (0)