Skip to content

Commit

Permalink
fix: prepare in rollback usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Sep 12, 2022
1 parent ac5d575 commit 14713f1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 47 deletions.
3 changes: 2 additions & 1 deletion ci/release_notes.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Empty - please add release notes here
## Fix
- prepare wasn't checking out the correct file state in rollback use case
11 changes: 1 addition & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use anyhow::*;
use glob::*;
use serde::Deserialize;
use std::{
collections::{HashMap, HashSet},
fs::File,
io::{BufReader, Read},
path::{Path, PathBuf},
path::Path,
};

pub const MATCH_OPTIONS: glob::MatchOptions = glob::MatchOptions {
Expand Down Expand Up @@ -106,14 +105,6 @@ impl EnvironmentConfig {
.map(|path| glob::Pattern::new(&path).expect("Couldn't compile glob pattern"))
}

pub fn propagated_files(&self) -> impl Iterator<Item = PathBuf> {
let files: Vec<_> = self.propagated_files.to_vec();
files
.into_iter()
.flat_map(|file| glob(&file).expect("Couldn't resolve glob"))
.map(|res| res.expect("Couldn't list file"))
}

pub fn head_file_patterns(&self) -> impl Iterator<Item = glob::Pattern> + '_ {
self.head_files
.iter()
Expand Down
4 changes: 4 additions & 0 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ impl FileIdent {
self.0.chars().skip_while(|c| c != &'}').skip(2).collect()
}

pub fn propagated(&self) -> bool {
!self.0.starts_with("{latest}")
}

pub fn inner(self) -> String {
self.0
}
Expand Down
40 changes: 5 additions & 35 deletions src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,42 +111,12 @@ impl Workspace {
force_clean: bool,
) -> Result<()> {
let repo = Repo::open(gate)?;
let ignore_list = self.ignore_list();
let head_patterns: Vec<_> = env.head_file_patterns().collect();
repo.checkout_gate(&head_patterns, &ignore_list, force_clean)?;
for file_buf in env.propagated_files() {
let file = file_buf.as_path();
if file.is_file()
&& !ignore_list
.iter()
.any(|p| p.matches_path_with(file, MATCH_OPTIONS))
&& !head_patterns
.iter()
.any(|p| p.matches_path_with(file, MATCH_OPTIONS))
{
std::fs::remove_file(file_buf).expect("Couldn't remove file");
}
}
if let Some(previous_env) = env.propagated_from() {
let patterns: Vec<_> = env.propagated_file_patterns().collect();
if let Some(env_state) = self.db.get_target_propagated_state(
&env.name,
env.ignore_queue,
previous_env,
&patterns,
) {
for (ident, state) in env_state.files.iter() {
let name = ident.name();
if patterns
.iter()
.any(|p| p.matches_with(&name, MATCH_OPTIONS))
&& !head_patterns
.iter()
.any(|p| p.matches_with(&name, MATCH_OPTIONS))
{
repo.checkout_file_from(&name, &state.from_commit)?;
}
}
repo.checkout_gate(&head_patterns, &self.ignore_list(), force_clean)?;
let new_env_state = self.construct_env_state(&repo, env, false)?;
for (ident, state) in new_env_state.files.iter() {
if ident.propagated() {
repo.checkout_file_from(&ident.name(), &state.from_commit)?;
}
}
Ok(())
Expand Down
4 changes: 3 additions & 1 deletion test/integration/gates.bats
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,7 @@ queued: HEAD
propagated: ${trigger1}
EOF

cmd -g `fixture`/cepler-gates.yml check -e propagated
cmd -g `fixture`/cepler-gates.yml check -e propagated | grep "${trigger1}"
cmd -g `fixture`/cepler-gates.yml prepare -e propagated
grep "trigger1" `fixture`/queued.yml
}

0 comments on commit 14713f1

Please sign in to comment.