Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ jobs:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
components: rustfmt, clippy

- name: Restore Cargo cache
uses: Swatinem/rust-cache@v2

- name: Check formatting
run: cargo fmt --all --check

- name: Run cargo clippy
run: cargo clippy --locked --all-targets -- -D warnings

- name: Run cargo check
run: cargo check --locked --all-targets

Expand Down
27 changes: 26 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,34 @@ jobs:
exit 1
fi

test:
name: Test
needs: verify_tag_on_main
runs-on: ubuntu-24.04
steps:
- name: Check out repository
uses: actions/checkout@v5

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Restore Cargo cache
uses: Swatinem/rust-cache@v2

- name: Check formatting
run: cargo fmt --all --check

- name: Run cargo clippy
run: cargo clippy --locked --all-targets -- -D warnings

- name: Run cargo test
run: cargo test --locked --release

build:
name: Build ${{ matrix.target }}
needs: verify_tag_on_main
needs: [verify_tag_on_main, test]
runs-on: ${{ matrix.runs_on }}
strategy:
fail-fast: false
Expand Down
12 changes: 6 additions & 6 deletions src/cli/branch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ pub struct BranchArgs {
pub fn execute(args: BranchArgs) -> io::Result<CommandOutcome> {
let outcome = branch::run(&args.clone().into())?;

if outcome.status.success() {
if let Some(node) = &outcome.created_node {
println!("Created and switched to '{}'.", node.branch_name);
println!();
println!("{}", super::tree::render_branch_lineage(&outcome.lineage));
}
if outcome.status.success()
&& let Some(node) = &outcome.created_node
{
println!("Created and switched to '{}'.", node.branch_name);
println!();
println!("{}", super::tree::render_branch_lineage(&outcome.lineage));
}

Ok(CommandOutcome {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl AnimationTerminal {

pub fn finish(&mut self, frame: &str) -> io::Result<()> {
self.render(frame)?;
write!(self.stdout, "{ANSI_SHOW_CURSOR}\n")?;
writeln!(self.stdout, "{ANSI_SHOW_CURSOR}")?;
self.stdout.flush()?;
self.active = false;
Ok(())
Expand Down
12 changes: 6 additions & 6 deletions src/cli/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,9 +1024,9 @@ fn format_remote_push_plan(plan: &sync::RemotePushPlan) -> String {

for action in &plan.actions {
let action_label = match action.kind {
RemotePushActionKind::CreateRemoteBranch => "create",
RemotePushActionKind::UpdateRemoteBranch => "push",
RemotePushActionKind::ForceUpdateRemoteBranch => "force-push",
RemotePushActionKind::Create => "create",
RemotePushActionKind::Update => "push",
RemotePushActionKind::ForceUpdate => "force-push",
};
lines.push(format!(
"- {action_label} {} on {}",
Expand Down Expand Up @@ -1071,9 +1071,9 @@ fn format_partial_remote_push_output(header: &str, outcome: &RemotePushOutcome)
let mut lines = vec![header.to_string()];
for action in &outcome.pushed_actions {
let action_label = match action.kind {
RemotePushActionKind::CreateRemoteBranch => "created",
RemotePushActionKind::UpdateRemoteBranch => "pushed",
RemotePushActionKind::ForceUpdateRemoteBranch => "force-pushed",
RemotePushActionKind::Create => "created",
RemotePushActionKind::Update => "pushed",
RemotePushActionKind::ForceUpdate => "force-pushed",
};
lines.push(format!(
"- {action_label} {} on {}",
Expand Down
6 changes: 3 additions & 3 deletions src/cli/sync/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ fn format_status_text(status: &SyncStatus) -> String {
} => format!(
"{} {branch_name} on {remote_name}",
match kind {
RemotePushActionKind::CreateRemoteBranch => "Creating remote branch",
RemotePushActionKind::UpdateRemoteBranch => "Pushing",
RemotePushActionKind::ForceUpdateRemoteBranch => "Force-pushing",
RemotePushActionKind::Create => "Creating remote branch",
RemotePushActionKind::Update => "Pushing",
RemotePushActionKind::ForceUpdate => "Force-pushing",
}
),
SyncStatus::DeletingBranch { branch_name } => format!("Deleting {branch_name}"),
Expand Down
8 changes: 4 additions & 4 deletions src/cli/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ pub(super) fn render_focused_context_tree(
) -> io::Result<String> {
let mut view = tree::focused_context_view(branch_name)?;

if let Some((current_branch_name, suffix)) = suffix_for_current_branch {
if view.current_branch_name.as_deref() == Some(current_branch_name) {
view.current_branch_suffix = Some(suffix.to_string());
}
if let Some((current_branch_name, suffix)) = suffix_for_current_branch
&& view.current_branch_name.as_deref() == Some(current_branch_name)
{
view.current_branch_suffix = Some(suffix.to_string());
}

Ok(render::render_stack_tree(&view))
Expand Down
26 changes: 13 additions & 13 deletions src/cli/tree/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ pub fn render_stack_tree(view: &TreeView) -> String {
.collect::<Vec<_>>()
.join("\n");

if !view.is_current_visible {
if let Some(current_branch) = &view.current_branch_name {
let label = match &view.current_branch_suffix {
Some(suffix) => format!("{current_branch} {suffix}"),
None => current_branch.clone(),
};
if !view.is_current_visible
&& let Some(current_branch) = &view.current_branch_name
{
let label = match &view.current_branch_suffix {
Some(suffix) => format!("{current_branch} {suffix}"),
None => current_branch.clone(),
};

rendered.push_str("\n\n");
rendered.push_str(&format!(
"{} {}",
Accent::BranchRef.paint_ansi(markers::CURRENT_BRANCH),
Accent::BranchRef.paint_ansi(&label)
));
}
rendered.push_str("\n\n");
rendered.push_str(&format!(
"{} {}",
Accent::BranchRef.paint_ansi(markers::CURRENT_BRANCH),
Accent::BranchRef.paint_ansi(&label)
));
}

rendered
Expand Down
1 change: 1 addition & 0 deletions src/core/clean/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ where
})
}

#[allow(clippy::too_many_arguments)]
fn process_clean_candidate<F>(
session: &mut crate::core::store::StoreSession,
original_branch: &str,
Expand Down
2 changes: 1 addition & 1 deletion src/core/clean/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ fn apply_deleted_step_projection(
let mut projected_state = state.clone();

for step in deleted_steps {
deleted_local::simulate_deleted_local_step(&mut projected_state, &step)?;
deleted_local::simulate_deleted_local_step(&mut projected_state, step)?;
}

Ok(projected_state)
Expand Down
10 changes: 5 additions & 5 deletions src/core/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ fn parse_git_log_output(stdout: &str) -> Vec<CommitEntry> {
fn parse_commit_metadata(remainder: &str) -> (bool, Vec<String>, String) {
let trimmed = remainder.trim_start();

if let Some(decorated) = trimmed.strip_prefix('(') {
if let Some((decorations, title)) = decorated.split_once(") ") {
let (is_head, refs) = parse_decorations(decorations);
return (is_head, refs, title.to_string());
}
if let Some(decorated) = trimmed.strip_prefix('(')
&& let Some((decorations, title)) = decorated.split_once(") ")
{
let (is_head, refs) = parse_decorations(decorations);
return (is_head, refs, title.to_string());
}

(false, Vec::new(), trimmed.to_string())
Expand Down
10 changes: 5 additions & 5 deletions src/core/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ where
let text = String::from_utf8_lossy(&chunk[..read]);
stderr_output.push_str(&text);

if let Some(progress) = parse_latest_rebase_progress(&stderr_output) {
if last_progress != Some(progress) {
on_progress(progress)?;
last_progress = Some(progress);
}
if let Some(progress) = parse_latest_rebase_progress(&stderr_output)
&& last_progress != Some(progress)
{
on_progress(progress)?;
last_progress = Some(progress);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/core/merge/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ fn run_squash_merge(
let commit_output = git::commit_with_message_file(&message_path);
let remove_result = fs::remove_file(&message_path);
let commit_output = commit_output?;
if let Err(err) = remove_result {
return Err(err);
}
remove_result?;

Ok(commit_output)
}
Expand Down
20 changes: 10 additions & 10 deletions src/core/reparent/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ pub(crate) fn plan(options: &ReparentOptions) -> io::Result<ReparentPlan> {
let new_parent =
branch::resolve_parent_ref(&session.state, &session.config, parent_branch_name)?;

if let ParentRef::Branch { node_id: parent_id } = new_parent {
if graph.active_descendant_ids(node.id).contains(&parent_id) {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!(
"cannot reparent '{}' onto descendant '{}'",
branch_name, parent_branch_name
),
));
}
if let ParentRef::Branch { node_id: parent_id } = new_parent
&& graph.active_descendant_ids(node.id).contains(&parent_id)
{
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!(
"cannot reparent '{}' onto descendant '{}'",
branch_name, parent_branch_name
),
));
}

let restack_plan = restack::previews_for_actions(&restack::plan_after_branch_reparent(
Expand Down
1 change: 1 addition & 0 deletions src/core/store/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ pub enum ParentRef {

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
#[allow(clippy::enum_variant_names)]
pub enum DaggerEvent {
BranchCreated(BranchCreatedEvent),
BranchAdopted(BranchAdoptedEvent),
Expand Down
40 changes: 16 additions & 24 deletions src/core/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ pub struct SyncOutcome {

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RemotePushActionKind {
CreateRemoteBranch,
UpdateRemoteBranch,
ForceUpdateRemoteBranch,
Create,
Update,
ForceUpdate,
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -806,6 +806,7 @@ where
)
}

#[allow(clippy::too_many_arguments)]
fn execute_sync_restack_step<F>(
session: &mut crate::core::store::StoreSession,
original_branch: &str,
Expand Down Expand Up @@ -1367,10 +1368,10 @@ where
kind: action.kind,
})?;
let push_output = match action.kind {
RemotePushActionKind::CreateRemoteBranch | RemotePushActionKind::UpdateRemoteBranch => {
RemotePushActionKind::Create | RemotePushActionKind::Update => {
git::push_branch_to_remote(&action.target)?
}
RemotePushActionKind::ForceUpdateRemoteBranch => {
RemotePushActionKind::ForceUpdate => {
git::force_push_branch_to_remote_with_lease(&action.target)?
}
};
Expand Down Expand Up @@ -1513,7 +1514,7 @@ fn plan_remote_push_action(
else {
return Ok(Some(RemotePushAction {
target,
kind: RemotePushActionKind::CreateRemoteBranch,
kind: RemotePushActionKind::Create,
}));
};

Expand All @@ -1525,7 +1526,7 @@ fn plan_remote_push_action(
if allow_force_update {
return Ok(Some(RemotePushAction {
target,
kind: RemotePushActionKind::ForceUpdateRemoteBranch,
kind: RemotePushActionKind::ForceUpdate,
}));
}

Expand All @@ -1534,7 +1535,7 @@ fn plan_remote_push_action(
if git::merge_base(&remote_tracking_branch_ref, branch_name)? == remote_oid {
return Ok(Some(RemotePushAction {
target,
kind: RemotePushActionKind::UpdateRemoteBranch,
kind: RemotePushActionKind::Update,
}));
}

Expand Down Expand Up @@ -1654,15 +1655,9 @@ mod tests {

assert_eq!(plan.actions.len(), 2);
assert_eq!(plan.actions[0].target.branch_name, "feat/auth");
assert_eq!(
plan.actions[0].kind,
RemotePushActionKind::ForceUpdateRemoteBranch
);
assert_eq!(plan.actions[0].kind, RemotePushActionKind::ForceUpdate);
assert_eq!(plan.actions[1].target.branch_name, "feat/auth-ui");
assert_eq!(
plan.actions[1].kind,
RemotePushActionKind::CreateRemoteBranch
);
assert_eq!(plan.actions[1].kind, RemotePushActionKind::Create);
assert!(
plan.actions
.iter()
Expand Down Expand Up @@ -1690,10 +1685,7 @@ mod tests {

assert_eq!(plan.actions.len(), 1);
assert_eq!(plan.actions[0].target.branch_name, "feat/auth");
assert_eq!(
plan.actions[0].kind,
RemotePushActionKind::UpdateRemoteBranch
);
assert_eq!(plan.actions[0].kind, RemotePushActionKind::Update);
});
}

Expand Down Expand Up @@ -1908,14 +1900,14 @@ mod tests {
remote_name: "origin".into(),
branch_name: "feat/auth".into(),
},
kind: RemotePushActionKind::CreateRemoteBranch,
kind: RemotePushActionKind::Create,
},
super::RemotePushAction {
target: BranchPushTarget {
remote_name: "origin".into(),
branch_name: "feat/auth-ui".into(),
},
kind: RemotePushActionKind::CreateRemoteBranch,
kind: RemotePushActionKind::Create,
},
],
};
Expand All @@ -1935,12 +1927,12 @@ mod tests {
SyncStatus::PushingRemoteBranch {
branch_name: "feat/auth".into(),
remote_name: "origin".into(),
kind: RemotePushActionKind::CreateRemoteBranch,
kind: RemotePushActionKind::Create,
},
SyncStatus::PushingRemoteBranch {
branch_name: "feat/auth-ui".into(),
remote_name: "origin".into(),
kind: RemotePushActionKind::CreateRemoteBranch,
kind: RemotePushActionKind::Create,
},
]
);
Expand Down
Loading