Ensure that we delete the version dir on errors
This allows to avoid incrementing the version number
This commit is contained in:
parent
3ec49e0230
commit
40b30459ca
1 changed files with 23 additions and 6 deletions
29
src/main.rs
29
src/main.rs
|
|
@ -262,7 +262,18 @@ fn main() -> Result<()> {
|
||||||
.to_str()
|
.to_str()
|
||||||
.ok_or(miette!("Temp dir is not utf-8"))?;
|
.ok_or(miette!("Temp dir is not utf-8"))?;
|
||||||
|
|
||||||
let format_patch = |extra_args: &[&str]| {
|
struct VersionDir {
|
||||||
|
path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for VersionDir {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
std::fs::remove_dir_all(&self.path)
|
||||||
|
.expect("could not delete version dir on error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let format_patch = |extra_args: &[&str]| -> Result<_> {
|
||||||
let mut format_patch_args = vec!["format-patch", "-o", &version_dir];
|
let mut format_patch_args = vec!["format-patch", "-o", &version_dir];
|
||||||
let version_str = version.map(|s| s.to_string());
|
let version_str = version.map(|s| s.to_string());
|
||||||
|
|
||||||
|
|
@ -276,10 +287,14 @@ fn main() -> Result<()> {
|
||||||
format_patch_args.extend_from_slice(extra_args);
|
format_patch_args.extend_from_slice(extra_args);
|
||||||
format_patch_args.extend(args.extra_args.iter().map(|s| s.deref()));
|
format_patch_args.extend(args.extra_args.iter().map(|s| s.deref()));
|
||||||
|
|
||||||
git_cd(&format_patch_args)
|
git_cd(&format_patch_args)?;
|
||||||
|
|
||||||
|
Ok(VersionDir {
|
||||||
|
path: version_dir.into(),
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(interdiff) = args.diff {
|
let _version_dir = if let Some(interdiff) = args.diff {
|
||||||
let base = args
|
let base = args
|
||||||
.base_diff
|
.base_diff
|
||||||
.or(config.interdiff_base)
|
.or(config.interdiff_base)
|
||||||
|
|
@ -371,10 +386,10 @@ fn main() -> Result<()> {
|
||||||
wt.exec(&apply_args)?;
|
wt.exec(&apply_args)?;
|
||||||
|
|
||||||
let interdiff_branch = format!("--interdiff={}", branch.name);
|
let interdiff_branch = format!("--interdiff={}", branch.name);
|
||||||
format_patch(&[&interdiff_branch])?;
|
format_patch(&[&interdiff_branch])?
|
||||||
} else {
|
} else {
|
||||||
format_patch(&[])?;
|
format_patch(&[])?
|
||||||
}
|
};
|
||||||
|
|
||||||
let cover_letter = branch_dir.join(COVER_LETTER_NAME);
|
let cover_letter = branch_dir.join(COVER_LETTER_NAME);
|
||||||
if !cover_letter.exists() {
|
if !cover_letter.exists() {
|
||||||
|
|
@ -446,6 +461,8 @@ fn main() -> Result<()> {
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.wrap_err("Could not save cover letter")?;
|
.wrap_err("Could not save cover letter")?;
|
||||||
|
|
||||||
|
std::mem::forget(_version_dir);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Command::List(list) => {
|
Command::List(list) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue