Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
175c1d016d |
Generated
+1
-1
@@ -1503,7 +1503,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "worklane"
|
name = "worklane"
|
||||||
version = "0.17.1"
|
version = "0.17.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "worklane"
|
name = "worklane"
|
||||||
version = "0.17.1"
|
version = "0.17.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
+15
-5
@@ -256,10 +256,6 @@ pub fn cmd_add(args: &AddArgs, start: &Path) -> Result<()> {
|
|||||||
let filename = format!("{}_{}.md", id, slug);
|
let filename = format!("{}_{}.md", id, slug);
|
||||||
let filepath = backlog_dir.join(&filename);
|
let filepath = backlog_dir.join(&filename);
|
||||||
|
|
||||||
if filepath.exists() {
|
|
||||||
return Err(anyhow!("A ticket with this title already exists."));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Joined with a single newline, so an empty value is how a caller spells a
|
// Joined with a single newline, so an empty value is how a caller spells a
|
||||||
// paragraph break and an all-blank description is no description at all.
|
// paragraph break and an all-blank description is no description at all.
|
||||||
let description = trim_blank_ends(description);
|
let description = trim_blank_ends(description);
|
||||||
@@ -327,7 +323,21 @@ pub fn cmd_add(args: &AddArgs, start: &Path) -> Result<()> {
|
|||||||
);
|
);
|
||||||
body.push('\n');
|
body.push('\n');
|
||||||
|
|
||||||
fs::write(&filepath, body)?;
|
// No existence check ahead of this. The name carries a uuid generated a few lines
|
||||||
|
// up, so a collision is not something that happens, and the branch that used to
|
||||||
|
// guard the write claimed the *title* was taken, which is the opposite of what the
|
||||||
|
// format allows: duplicate titles are supported and `add_allows_duplicate_titles`
|
||||||
|
// pins it. `cmd_campaign_add` deliberately does not carry it either. What is left is
|
||||||
|
// the write's own failure, named with the ticket and the path the way the other
|
||||||
|
// writes in the tree name them.
|
||||||
|
fs::write(&filepath, body).map_err(|e| {
|
||||||
|
anyhow!(
|
||||||
|
"Could not write ticket '{}' at {}: {}",
|
||||||
|
title,
|
||||||
|
filepath.display(),
|
||||||
|
e
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
println!("Created ticket: {}", filename);
|
println!("Created ticket: {}", filename);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -561,3 +561,39 @@ fn read_only_ticket(dir: &Path) -> String {
|
|||||||
|
|
||||||
fs::read_to_string(file.path()).unwrap()
|
fs::read_to_string(file.path()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn chmod(path: &Path, mode: u32) {
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
|
let mut perms = fs::metadata(path).unwrap().permissions();
|
||||||
|
perms.set_mode(mode);
|
||||||
|
fs::set_permissions(path, perms).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A duplicate title is not a failure, so the only thing left to refuse is the write
|
||||||
|
/// itself, and it is named with the ticket and the path rather than raised as a bare io
|
||||||
|
/// error. The branch this replaces could not fire at all: the filename carries a fresh
|
||||||
|
/// uuid, and its message claimed the title was taken.
|
||||||
|
#[test]
|
||||||
|
fn add_names_the_ticket_and_the_path_when_the_write_fails() {
|
||||||
|
let temp = TempDir::new().unwrap();
|
||||||
|
let worklane = setup_worklane(&temp);
|
||||||
|
let backlog = worklane.join("backlog");
|
||||||
|
|
||||||
|
chmod(&backlog, 0o555);
|
||||||
|
|
||||||
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
let assert = cmd
|
||||||
|
.current_dir(temp.path())
|
||||||
|
.args(["add", "--title", "Unwritable"])
|
||||||
|
.assert()
|
||||||
|
.failure();
|
||||||
|
|
||||||
|
let stderr = String::from_utf8(assert.get_output().stderr.clone()).unwrap();
|
||||||
|
assert!(stderr.contains("Unwritable"), "{stderr}");
|
||||||
|
assert!(stderr.contains("unwritable.md"), "{stderr}");
|
||||||
|
assert!(!stderr.contains("already exists"), "{stderr}");
|
||||||
|
|
||||||
|
chmod(&backlog, 0o755);
|
||||||
|
assert_eq!(fs::read_dir(&backlog).unwrap().count(), 0);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user