Skip to content

Commit 6218c59

Browse files
committed
fix(bolt): correctly hash untracked files
1 parent be998a3 commit 6218c59

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

lib/bolt/core/src/context/project.rs

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,26 +120,14 @@ impl ProjectContextData {
120120
Self::load_root_dir(&mut svc_ctxs_map, path.clone()).await;
121121

122122
// Compute the git diff between the current branch and the local changes
123-
let mut cmd = Command::new("git");
124-
cmd.current_dir(path).arg("diff").arg("--minimal");
125-
source_diff.push_str(
126-
&cmd.exec_string_with_err("Failed to get source hash", true)
127-
.await
128-
.unwrap(),
129-
);
123+
source_diff.push_str(&get_source_diff(&path).await.unwrap());
130124
}
131125

132126
// Load main project after sub projects so it overrides sub project services
133127
Self::load_root_dir(&mut svc_ctxs_map, project_root.clone()).await;
134128

135129
// Compute the git diff between the current branch and the local changes
136-
let mut cmd = Command::new("git");
137-
cmd.current_dir(&project_root).arg("diff").arg("--minimal");
138-
source_diff.push_str(
139-
&cmd.exec_string_with_err("Failed to get source hash", true)
140-
.await
141-
.unwrap(),
142-
);
130+
source_diff.push_str(&get_source_diff(&project_root).await.unwrap());
143131

144132
// If there is no diff, use the git commit hash
145133
let source_hash = if source_diff.is_empty() {
@@ -1174,3 +1162,41 @@ impl ProjectContextData {
11741162
Ok(value_str)
11751163
}
11761164
}
1165+
1166+
async fn get_source_diff(path: &Path) -> Result<String> {
1167+
use tokio::io::AsyncReadExt;
1168+
use tokio::process::Command;
1169+
1170+
// Get git diff
1171+
let diff_output = Command::new("git")
1172+
.current_dir(path)
1173+
.args(&["--no-pager", "diff", "HEAD", "--minimal"])
1174+
.output()
1175+
.await?;
1176+
let mut result = String::from_utf8(diff_output.stdout)?;
1177+
1178+
// Add diff for untracked files
1179+
let ls_files_output = Command::new("git")
1180+
.current_dir(path)
1181+
.args(&[
1182+
"--no-pager",
1183+
"ls-files",
1184+
"-z",
1185+
"--others",
1186+
"--exclude-standard",
1187+
])
1188+
.output()
1189+
.await?;
1190+
for file in String::from_utf8(ls_files_output.stdout)?.split('\0') {
1191+
if !file.is_empty() {
1192+
let mut file_content = String::new();
1193+
tokio::fs::File::open(path.join(file))
1194+
.await?
1195+
.read_to_string(&mut file_content)
1196+
.await?;
1197+
result.push_str(&file_content);
1198+
}
1199+
}
1200+
1201+
Ok(result)
1202+
}

lib/bolt/core/src/dep/cargo/cli.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ pub async fn build_tests<'a, T: AsRef<str>>(
379379
[ -z "${{CARGO_TARGET_DIR+x}}" ] && export CARGO_TARGET_DIR=$(readlink -f ./target)
380380
# Used for Tokio Console. See https://github.com/tokio-rs/console#using-it
381381
export RUSTFLAGS="--cfg tokio_unstable"
382+
export CARGO_TERM_COLOR=always
382383
383384
{build_calls}
384385
"#,
@@ -498,8 +499,6 @@ pub async fn build_tests<'a, T: AsRef<str>>(
498499
cmd.arg("build");
499500
cmd.arg("--progress").arg("plain");
500501
cmd.arg("-f").arg(dockerfile_path);
501-
// Prints plain console output for debugging
502-
// cmd.arg("--progress=plain");
503502
cmd.arg("-t").arg(&image_tag);
504503
cmd.arg(".");
505504

0 commit comments

Comments
 (0)