new: ignore vendored rust artifacts in the generated gitignore

This commit is contained in:
2026-09-17 10:37:58 +02:00
parent bac82f0afe
commit bc3d07abaa
4 changed files with 183 additions and 20 deletions
+51
View File
@@ -137,6 +137,15 @@ pub trait Template: Sync {
Vec::new()
}
/// Root `.gitignore` entries the template contributes in every mode
/// (the skeleton-mode build-artifact entries of
/// [`crate::new::debian::ROOT_GITIGNORE_ENTRIES`] are separate), merged
/// into the root `.gitignore` after the files are written — missing
/// ones appended, an existing file never overwritten. Default: none.
fn gitignore_entries(&self, _opts: &NewOptions) -> Vec<String> {
Vec::new()
}
/// Extra defaults derived from project metadata in `dir` (detect.rs);
/// `None` when the project carries nothing this template can read.
fn probe(&self, _dir: &Path) -> Option<ProbeResult> {
@@ -248,6 +257,48 @@ mod tests {
);
}
/// Only the rust template contributes root `.gitignore` entries of its
/// own — exactly the vendoring pair, and unconditionally (its vendoring
/// hook runs in every mode); every other template contributes nothing.
#[test]
fn gitignore_entries_are_rust_only() {
let o = NewOptions {
name: "mytool".into(),
template: TemplateId::Rust,
source_dir: SourceDir::Here,
upstream_version: "0.1.0".into(),
revision: 1,
summary: "A tool".into(),
long_description: "A tool".into(),
homepage: None,
license: crate::new::options::License::Mit,
command: "mytool".into(),
maintainer: ("Jane".into(), "jane@example.com".into()),
dist: "ubuntu".into(),
series: "resolute".into(),
release: false,
depends: Vec::new(),
source_format: crate::new::options::SourceFormat::Quilt,
orig: None,
git: false,
autopkgtest: false,
pkg_config: false,
watch: None,
};
for id in TemplateId::all() {
let entries = get(id).unwrap().gitignore_entries(&o);
if id == TemplateId::Rust {
assert_eq!(
entries,
vec!["vendor/".to_string(), ".cargo/config.toml".to_string()]
);
} else {
assert!(entries.is_empty(), "{id} contributes {entries:?}");
}
}
}
/// The final `debian/rules` of every template must be valid-looking
/// make: `#!/usr/bin/make -f` shebang, exactly one `%:` target whose
/// recipe is the template's dh line, tab-indented recipes only, and no