Skip to content

Commit dc20918

Browse files
committed
Never overwrite a file the project already maintains
Running pr against a real repository proposed replacing its hand-written .env.example with a generated stub. The existing file explained that VITE_* values are inlined into the public bundle and are identifiers rather than secrets, warned against putting an Appwrite API key there, and carried a working default. The generated template had none of that and added a spurious DEV entry. A generated template is a floor for a project that has none, not an improvement on one a person wrote. pr now skips any artifact whose path already exists, warns which files it left alone, and fails rather than opening an empty pull request when every artifact already exists. Found by running the tool against Barter, not by any test.
1 parent 95de9af commit dc20918

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

crates/launchguard-cli/src/main.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,9 +830,32 @@ async fn pull_request(options: PullRequestOptions<'_>) -> Result<()> {
830830
let intent = IntentGenerator
831831
.generate(&profile, options.provider, None)
832832
.context("failed to capture deployment intent")?;
833-
let files =
833+
let generated =
834834
generate_configuration(&intent).context("failed to generate deployment configuration")?;
835835

836+
// A file the project already maintains is left alone. A generated template
837+
// is a floor for a project that has none, never an improvement on one a
838+
// person wrote, and silently replacing hand-written guidance with a
839+
// generic stub is a regression no reviewer asked for.
840+
let mut files = Vec::new();
841+
let mut preserved = Vec::new();
842+
for file in generated {
843+
if repository.root().join(&file.path).exists() {
844+
preserved.push(file.path.clone());
845+
} else {
846+
files.push(file);
847+
}
848+
}
849+
for path in &preserved {
850+
warn!(path = path.as_str(), "keeping the existing file unchanged");
851+
}
852+
if files.is_empty() {
853+
return Err(anyhow!(
854+
"every generated file already exists in the repository ({}); nothing to publish",
855+
preserved.join(", ")
856+
));
857+
}
858+
836859
let capability = CapabilityProbe::default().detect().await.ok();
837860
let mut decision = PublicationGate
838861
.evaluate(

0 commit comments

Comments
 (0)