Skip to content

Commit 53f692d

Browse files
authored
Remove the dependency on git ls-files from cli/build.rs (#3568)
# Description of Changes We technically don't need to `git ls-files` when getting the CLI templates because when we compile the release builds we work with a clean git clone, thus it's unlikely any untracked files will be created in the templates directory. # API and ABI breaking changes None # Expected complexity level and risk 1 # Testing - [x] I've manually checked that the init command still generates the templates properly
1 parent 0491b5e commit 53f692d

File tree

1 file changed

+4
-51
lines changed

1 file changed

+4
-51
lines changed

crates/cli/build.rs

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ fn nix_injected_commit_hash() -> Option<String> {
3434
}
3535
}
3636

37-
fn is_nix_build() -> bool {
38-
nix_injected_commit_hash().is_some()
39-
}
40-
4137
fn find_git_hash() -> String {
4238
nix_injected_commit_hash().unwrap_or_else(|| {
4339
// When we're *not* building in Nix, we can assume that git metadata is still present in the filesystem,
@@ -160,10 +156,10 @@ fn generate_template_files() {
160156
}
161157

162158
fn generate_template_entry(code: &mut String, template_path: &Path, source: &str, manifest_dir: &Path) {
163-
let (git_files, resolved_base) = get_git_tracked_files(template_path, manifest_dir);
159+
let (template_files, resolved_base) = list_all_files(template_path, manifest_dir);
164160

165-
if git_files.is_empty() {
166-
panic!("Template '{}' has no git-tracked files! Check that the directory exists and contains files tracked by git.", source);
161+
if template_files.is_empty() {
162+
panic!("Template '{}' has no files, check if the path is correct", source);
167163
}
168164

169165
// Example: /Users/user/SpacetimeDB
@@ -196,7 +192,7 @@ fn generate_template_entry(code: &mut String, template_path: &Path, source: &str
196192
code.push_str(" {\n");
197193
code.push_str(" let mut files = HashMap::new();\n");
198194

199-
for file_path in git_files {
195+
for file_path in template_files {
200196
// Example file_path: modules/quickstart-chat/src/lib.rs (relative to repo root)
201197
// Example resolved_base: modules/quickstart-chat
202198
// Example relative_path: src/lib.rs
@@ -259,18 +255,6 @@ fn generate_template_entry(code: &mut String, template_path: &Path, source: &str
259255
code.push_str(" }\n\n");
260256
}
261257

262-
/// Get a list of files tracked by git from a given directory
263-
fn get_git_tracked_files(path: &Path, manifest_dir: &Path) -> (Vec<PathBuf>, PathBuf) {
264-
if is_nix_build() {
265-
// When building in Nix, we already know that there are no untracked files in our source tree,
266-
// so we just list all of the files.
267-
list_all_files(path, manifest_dir)
268-
} else {
269-
// When building outside of Nix, we invoke `git` to list all the tracked files.
270-
get_git_tracked_files_via_cli(path, manifest_dir)
271-
}
272-
}
273-
274258
fn list_all_files(path: &Path, manifest_dir: &Path) -> (Vec<PathBuf>, PathBuf) {
275259
let manifest_dir = manifest_dir.canonicalize().unwrap_or_else(|err| {
276260
panic!(
@@ -346,37 +330,6 @@ fn make_repo_root_relative(full_path: &Path, repo_root: &Path) -> PathBuf {
346330
})
347331
}
348332

349-
fn get_git_tracked_files_via_cli(path: &Path, manifest_dir: &Path) -> (Vec<PathBuf>, PathBuf) {
350-
let repo_root = get_repo_root();
351-
let repo_root = repo_root.canonicalize().unwrap_or_else(|err| {
352-
panic!(
353-
"Failed to canonicalize repo_root path {}: {err:#?}",
354-
repo_root.display(),
355-
)
356-
});
357-
358-
let resolved_path = make_repo_root_relative(&get_full_path_within_manifest_dir(path, manifest_dir), &repo_root);
359-
360-
let output = Command::new("git")
361-
.args(["ls-files", resolved_path.to_str().unwrap()])
362-
.current_dir(repo_root)
363-
.output()
364-
.expect("Failed to execute git ls-files");
365-
366-
if !output.status.success() {
367-
return (Vec::new(), resolved_path);
368-
}
369-
370-
let stdout = String::from_utf8(output.stdout).unwrap();
371-
let files: Vec<PathBuf> = stdout
372-
.lines()
373-
.filter(|line| !line.is_empty())
374-
.map(PathBuf::from)
375-
.collect();
376-
377-
(files, resolved_path)
378-
}
379-
380333
fn get_repo_root() -> PathBuf {
381334
let manifest_dir = get_manifest_dir();
382335
// Cargo doesn't expose a way to get the workspace root, AFAICT (pgoldman 2025-10-31).

0 commit comments

Comments
 (0)