Skip to content

Commit ffbcb79

Browse files
committed
Fix CI
1 parent 9803a97 commit ffbcb79

File tree

3 files changed

+53
-18
lines changed

3 files changed

+53
-18
lines changed

AGENT.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Build/run
2424
- Build: `cargo build`
2525
- Run: `cargo run -- <subcommand>`
2626
- No tests yet.
27+
- After every code update, run `cargo fmt` and `cargo clippy`.
28+
- After changes, run relevant tests.
2729

2830
Potential future improvements
2931
- `terris prune` wrapper.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# terris
22

3-
[![Crates.io](https://img.shields.io/crates/v/terris.svg)](https://crates.io/crates/terris) [![CI](https://github.com/mfornet/terris/actions/workflows/ci.yml/badge.svg)](https://github.com/mfornet/terris/actions/workflows/ci.yml) [![License](https://img.shields.io/crates/l/terris.svg)](LICENSE)
3+
[![Crates.io](https://img.shields.io/crates/v/terris.svg)](https://crates.io/crates/terris) [![Docs.rs](https://img.shields.io/docsrs/terris.svg)](https://docs.rs/terris) [![CI](https://github.com/mfornet/terris/actions/workflows/ci.yml/badge.svg)](https://github.com/mfornet/terris/actions/workflows/ci.yml) [![License](https://img.shields.io/crates/l/terris.svg)](LICENSE)
44

55

66
A small, friendly Git worktree manager for everyday use.

src/main.rs

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ fn main() -> Result<()> {
6060
let cli = Cli::parse();
6161
match cli.command {
6262
Commands::List => cmd_list(),
63-
Commands::Create { name, path, branch, from } => cmd_create(&name, path, branch, from),
63+
Commands::Create {
64+
name,
65+
path,
66+
branch,
67+
from,
68+
} => cmd_create(&name, path, branch, from),
6469
Commands::Delete { target, force } => cmd_delete(&target, force),
6570
Commands::Path { target } => cmd_path(&target),
6671
}
@@ -73,7 +78,12 @@ fn cmd_list() -> Result<()> {
7378
Ok(())
7479
}
7580

76-
fn cmd_create(name: &str, path: Option<PathBuf>, branch: Option<String>, from: Option<String>) -> Result<()> {
81+
fn cmd_create(
82+
name: &str,
83+
path: Option<PathBuf>,
84+
branch: Option<String>,
85+
from: Option<String>,
86+
) -> Result<()> {
7787
let root = git_root()?;
7888
let cwd = std::env::current_dir().context("read current directory")?;
7989
let repo_name = root
@@ -87,17 +97,17 @@ fn cmd_create(name: &str, path: Option<PathBuf>, branch: Option<String>, from: O
8797
Some(p) => resolve_path(&cwd, p),
8898
None => default_worktree_path(&repo_name, &branch)?,
8999
};
90-
if is_default_path {
91-
if let Some(parent) = target_path.parent() {
92-
std::fs::create_dir_all(parent).with_context(|| {
93-
format!("create worktree base directory '{}'", parent.display())
94-
})?;
95-
}
100+
if is_default_path && let Some(parent) = target_path.parent() {
101+
std::fs::create_dir_all(parent)
102+
.with_context(|| format!("create worktree base directory '{}'", parent.display()))?;
96103
}
97104

98105
let branch_exists = git_branch_exists(&root, &branch)?;
99106
if branch_exists && from.is_some() {
100-
bail!("branch '{}' already exists; --from is only for new branches", branch);
107+
bail!(
108+
"branch '{}' already exists; --from is only for new branches",
109+
branch
110+
);
101111
}
102112

103113
let mut args: Vec<String> = vec!["worktree".into(), "add".into()];
@@ -232,11 +242,23 @@ fn print_worktrees(worktrees: &[Worktree]) {
232242
let name_width = rows.iter().map(|r| r.0.len()).max().unwrap_or(4).max(4);
233243
let branch_width = rows.iter().map(|r| r.1.len()).max().unwrap_or(6).max(6);
234244

235-
println!("{:name_width$} {:branch_width$} {} {}", "NAME", "BRANCH", "PATH", "FLAGS",
236-
name_width = name_width, branch_width = branch_width);
245+
println!(
246+
"{:name_width$} {:branch_width$} PATH FLAGS",
247+
"NAME",
248+
"BRANCH",
249+
name_width = name_width,
250+
branch_width = branch_width
251+
);
237252
for (name, branch, path, flags) in rows {
238-
println!("{:name_width$} {:branch_width$} {} {}", name, branch, path, flags,
239-
name_width = name_width, branch_width = branch_width);
253+
println!(
254+
"{:name_width$} {:branch_width$} {} {}",
255+
name,
256+
branch,
257+
path,
258+
flags,
259+
name_width = name_width,
260+
branch_width = branch_width
261+
);
240262
}
241263
}
242264

@@ -252,7 +274,9 @@ fn worktree_name(wt: &Worktree) -> String {
252274
}
253275

254276
fn worktree_branch_short(wt: &Worktree) -> Option<&str> {
255-
wt.branch.as_deref().map(|b| b.strip_prefix("refs/heads/").unwrap_or(b))
277+
wt.branch
278+
.as_deref()
279+
.map(|b| b.strip_prefix("refs/heads/").unwrap_or(b))
256280
}
257281

258282
fn worktree_flags(wt: &Worktree) -> String {
@@ -286,7 +310,10 @@ fn resolve_worktree<'a>(target: &str, worktrees: &'a [Worktree]) -> Result<&'a W
286310
bail!("no worktree matches '{}'", target);
287311
}
288312
if matches.len() > 1 {
289-
let names: Vec<String> = matches.iter().map(|w| w.path.display().to_string()).collect();
313+
let names: Vec<String> = matches
314+
.iter()
315+
.map(|w| w.path.display().to_string())
316+
.collect();
290317
bail!("'{}' is ambiguous: {}", target, names.join(", "));
291318
}
292319
Ok(matches[0])
@@ -454,8 +481,14 @@ prunable stale
454481
let _ = std::fs::create_dir_all(&wt2_path);
455482

456483
let worktrees = vec![
457-
wt(wt1_path.to_string_lossy().as_ref(), Some("refs/heads/alpha")),
458-
wt(wt2_path.to_string_lossy().as_ref(), Some("refs/heads/alpha")),
484+
wt(
485+
wt1_path.to_string_lossy().as_ref(),
486+
Some("refs/heads/alpha"),
487+
),
488+
wt(
489+
wt2_path.to_string_lossy().as_ref(),
490+
Some("refs/heads/alpha"),
491+
),
459492
];
460493

461494
let by_path = resolve_worktree(wt1_path.to_string_lossy().as_ref(), &worktrees).unwrap();

0 commit comments

Comments
 (0)