Skip to content

Commit 70f4912

Browse files
krlvischacon
authored andcommitted
Display marked branches in but status and log
1 parent 25e3f77 commit 70f4912

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

crates/but/src/log/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(crate) fn commit_graph(repo_path: &Path, json: bool, short: bool) -> anyhow:
1717
but_rules::process_rules(ctx).ok(); // TODO: this is doing double work (dependencies can be reused)
1818
let stacks = stacks(ctx)?
1919
.iter()
20-
.filter_map(|s| s.id.map(|id| stack_details(ctx, id)))
20+
.filter_map(|s| s.id.map(|id| stack_details(ctx, id).map(|d| (id, d))))
2121
.filter_map(Result::ok)
2222
.collect::<Vec<_>>();
2323

@@ -30,7 +30,13 @@ pub(crate) fn commit_graph(repo_path: &Path, json: bool, short: bool) -> anyhow:
3030
}
3131

3232
let mut nesting = 0;
33-
for (i, stack) in stacks.iter().enumerate() {
33+
for (i, (stack_id, stack)) in stacks.iter().enumerate() {
34+
let marked = crate::mark::stack_marked(ctx, *stack_id).unwrap_or_default();
35+
let mut mark = if marked {
36+
Some("◀ Marked ▶".red().bold())
37+
} else {
38+
None
39+
};
3440
let mut second_consecutive = false;
3541
let mut stacked = false;
3642
for branch in stack.branch_details.iter() {
@@ -54,13 +60,15 @@ pub(crate) fn commit_graph(repo_path: &Path, json: bool, short: bool) -> anyhow:
5460
.underline()
5561
.blue();
5662
println!(
57-
"{}{}{} [{}] {}",
63+
"{}{}{} [{}] {} {}",
5864
"│ ".repeat(nesting),
5965
extra_space,
6066
line,
6167
branch.name.to_string().green().bold(),
62-
id
68+
id,
69+
mark.clone().unwrap_or_default()
6370
);
71+
mark = None; // show this on the first branch in the stack
6472
for (j, commit) in branch.upstream_commits.iter().enumerate() {
6573
let time_string = chrono::DateTime::from_timestamp_millis(commit.created_at as i64)
6674
.ok_or(anyhow::anyhow!("Could not parse timestamp"))?

crates/but/src/mark/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::rub::branch_name_to_stack_id;
44
use anyhow::bail;
55
use but_rules::Operation;
66
use but_settings::AppSettings;
7+
use but_workspace::StackId;
78
use gitbutler_command_context::CommandContext;
89
use gitbutler_project::Project;
910
pub(crate) fn handle(
@@ -45,6 +46,7 @@ fn mark_branch(ctx: &mut CommandContext, branch_name: String, delete: bool) -> a
4546
println!("Mark was removed");
4647
return Ok(());
4748
}
49+
// TODO: if there are other marks of this kind, get rid of them
4850
let stack_id = stack_id.expect("Cant find stack for this branch");
4951
let action = but_rules::Action::Explicit(Operation::Assign {
5052
target: but_rules::StackTarget::StackId(stack_id.to_string()),
@@ -60,3 +62,10 @@ fn mark_branch(ctx: &mut CommandContext, branch_name: String, delete: bool) -> a
6062
println!("Changes will be assigned to → {}", branch_name);
6163
Ok(())
6264
}
65+
66+
pub(crate) fn stack_marked(ctx: &mut CommandContext, stack_id: StackId) -> anyhow::Result<bool> {
67+
let rules = but_rules::list_rules(ctx)?
68+
.iter()
69+
.any(|r| r.target_stack_id() == Some(stack_id.to_string()));
70+
Ok(rules)
71+
}

0 commit comments

Comments
 (0)