Skip to content

Commit 0021f34

Browse files
committed
Display marked branches in but status and log
1 parent 0bec66e commit 0021f34

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

crates/but/src/log/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ pub(crate) fn commit_graph(repo_path: &Path, _json: bool) -> anyhow::Result<()>
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

2424
let mut nesting = 0;
25-
for (i, stack) in stacks.iter().enumerate() {
25+
for (i, (stack_id, stack)) in stacks.iter().enumerate() {
26+
let marked = crate::mark::stack_marked(ctx, *stack_id).unwrap_or_default();
27+
let mut mark = if marked {
28+
Some("◀ Marked ▶".red().bold())
29+
} else {
30+
None
31+
};
2632
let mut second_consecutive = false;
2733
let mut stacked = false;
2834
for branch in stack.branch_details.iter() {
@@ -46,13 +52,15 @@ pub(crate) fn commit_graph(repo_path: &Path, _json: bool) -> anyhow::Result<()>
4652
.underline()
4753
.blue();
4854
println!(
49-
"{}{}{} [{}] {}",
55+
"{}{}{} [{}] {} {}",
5056
"│ ".repeat(nesting),
5157
extra_space,
5258
line,
5359
branch.name.to_string().green().bold(),
54-
id
60+
id,
61+
mark.clone().unwrap_or_default()
5562
);
63+
mark = None; // show this on the first branch in the stack
5664
for (j, commit) in branch.upstream_commits.iter().enumerate() {
5765
let time_string = chrono::DateTime::from_timestamp_millis(commit.created_at as i64)
5866
.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+
}

crates/but/src/status/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ pub(crate) fn worktree(repo_path: &Path, _json: bool) -> anyhow::Result<()> {
5252
}
5353

5454
let unassigned = assignment::filter_by_stack_id(assignments_by_file.values(), &None);
55-
print_group(None, unassigned, &changes)?;
55+
print_group(None, unassigned, &changes, false)?;
5656

5757
for (stack_id, branch) in &stack_id_to_branch {
5858
let filtered =
5959
assignment::filter_by_stack_id(assignments_by_file.values(), &Some(*stack_id));
60-
print_group(Some(branch.as_str()), filtered, &changes)?;
60+
let marked = crate::mark::stack_marked(ctx, *stack_id).unwrap_or_default();
61+
print_group(Some(branch.as_str()), filtered, &changes, marked)?;
6162
}
6263
Ok(())
6364
}
@@ -66,6 +67,7 @@ pub fn print_group(
6667
group: Option<&str>,
6768
assignments: Vec<FileAssignment>,
6869
changes: &[TreeChange],
70+
marked: bool,
6971
) -> anyhow::Result<()> {
7072
let id = if let Some(group) = group {
7173
CliId::branch(group)
@@ -78,7 +80,17 @@ pub fn print_group(
7880
let group = &group
7981
.map(|s| format!("[{}]", s))
8082
.unwrap_or("<UNASSIGNED>".to_string());
81-
println!("{} {}", id, group.green().bold());
83+
let mark = if marked {
84+
Some("◀ Marked ▶".red().bold())
85+
} else {
86+
None
87+
};
88+
println!(
89+
"{} {} {}",
90+
id,
91+
group.green().bold(),
92+
mark.unwrap_or_default()
93+
);
8294
for fa in assignments {
8395
let state = status_from_changes(changes, fa.path.clone());
8496
let path = match state {

0 commit comments

Comments
 (0)