Skip to content

Commit

Permalink
feat(cargo-shuttle): beta deploy.deny_dirty config, allow dirty deplo…
Browse files Browse the repository at this point in the history
…ys by default (#1894)

* feat(cargo-shuttle): beta deploy.deny_dirty config, allow dirty deploys by default

* i got booled
  • Loading branch information
jonaro00 authored Oct 3, 2024
1 parent 8efada9 commit 1e90f20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
21 changes: 21 additions & 0 deletions cargo-shuttle/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ pub struct ProjectConfig {
// unused in cargo-shuttle, used in new platform builder.
// is used here to validate the type if used.
pub build_assets: Option<Vec<String>>,

pub deploy: Option<ProjectDeployConfig>,
}
/// Deployment command config
#[derive(Deserialize, Serialize, Default)]
pub struct ProjectDeployConfig {
/// set to true to deny deployments with uncommited changes. (can use `--allow-dirty`)
pub deny_dirty: Option<bool>,
}

/// .shuttle/config.toml schema (internal project-local config)
Expand Down Expand Up @@ -487,6 +495,19 @@ impl RequestContext {
.as_ref()
}

/// # Panics
/// Panics if the project configuration has not been loaded.
pub fn deny_dirty(&self) -> Option<bool> {
self.project
.as_ref()
.unwrap()
.as_ref()
.unwrap()
.deploy
.as_ref()
.and_then(|d| d.deny_dirty)
}

/// Check if the current project id has been loaded.
pub fn project_id_found(&self) -> bool {
self.project_internal
Expand Down
8 changes: 5 additions & 3 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2442,10 +2442,12 @@ impl Shuttle {
trace!(?repo_path, "found git repository");

let dirty = is_dirty(&repo);
if !args.allow_dirty && dirty.is_err() {
deployment_req.git_dirty = Some(dirty.is_err());

let check_dirty = !self.beta || self.ctx.deny_dirty().is_some_and(|d| d);
if check_dirty && !args.allow_dirty && dirty.is_err() {
bail!(dirty.unwrap_err());
}
deployment_req.git_dirty = Some(dirty.is_err());

if let Ok(head) = repo.head() {
// This is typically the name of the current branch
Expand Down Expand Up @@ -3219,7 +3221,7 @@ fn is_dirty(repo: &Repository) -> Result<()> {
}

writeln!(error).expect("to append error");
writeln!(error, "To proceed despite this and include the uncommitted changes, pass the `--allow-dirty` or `--ad` flag").expect("to append error");
writeln!(error, "To proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag (alias `--ad`)").expect("to append error");

bail!(error);
}
Expand Down

0 comments on commit 1e90f20

Please sign in to comment.