Skip to content

Commit 842f03b

Browse files
committed
Improve but status rendering
1 parent a8bcda1 commit 842f03b

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

crates/but/src/status/mod.rs

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub(crate) fn worktree(
7373
// Calculate common_merge_base data
7474
let stack = gitbutler_stack::VirtualBranchesHandle::new(ctx.project().gb_dir());
7575
let target = stack.get_default_target()?;
76-
let target_name = format!("[{}/{}]", target.branch.remote(), target.branch.branch());
76+
let target_name = format!("{}/{}", target.branch.remote(), target.branch.branch());
7777
let repo = ctx.gix_repo()?;
7878
let base_commit = repo.find_commit(target.sha.to_gix())?;
7979
let message = base_commit
@@ -120,9 +120,9 @@ pub(crate) fn worktree(
120120
)?;
121121
}
122122
println!(
123-
"◉ {} (common base) {} {}",
124-
common_merge_base_data.common_merge_base,
125-
common_merge_base_data.target_name,
123+
"◉ {} (common base) [{}] {}",
124+
common_merge_base_data.common_merge_base.dimmed(),
125+
common_merge_base_data.target_name.green().bold(),
126126
common_merge_base_data.message
127127
);
128128
Ok(())
@@ -164,7 +164,7 @@ fn print_assignments(assignments: &Vec<FileAssignment>, changes: &[TreeChange])
164164
if !locks.is_empty() {
165165
locks = format!("🔒 {locks}");
166166
}
167-
println!("│ {id} {path} {status} {locks}");
167+
println!("│ {id} {status} {path} {locks}");
168168
}
169169
}
170170

@@ -190,11 +190,21 @@ pub fn print_group(
190190
if !first {
191191
println!("│");
192192
}
193+
194+
let no_commits = if branch.commits.is_empty() {
195+
"(no commits)".to_string()
196+
} else {
197+
"".to_string()
198+
}
199+
.dimmed()
200+
.italic();
201+
193202
println!(
194-
"{} {} [{}] {}",
203+
"{}{} [{}] {} {}",
195204
notch,
196205
id,
197206
branch.name.to_string().green().bold(),
207+
no_commits,
198208
stack_mark.clone().unwrap_or_default()
199209
);
200210
*stack_mark = None; // Only show the stack mark for the first branch
@@ -216,75 +226,73 @@ pub fn print_group(
216226
"".normal()
217227
};
218228

229+
let mut message = commit
230+
.message
231+
.to_string()
232+
.replace('\n', " ")
233+
.chars()
234+
.take(50)
235+
.collect::<String>()
236+
.normal();
237+
if message.is_empty() {
238+
message = "(no commit message)".to_string().dimmed().italic();
239+
}
240+
241+
let commit_details = but_api::diff::commit_details(project.id, commit.id.into())?;
242+
let no_changes = if show_files && commit_details.changes.changes.is_empty() {
243+
"(no changes)".dimmed().italic()
244+
} else {
245+
"".to_string().normal()
246+
};
247+
219248
if verbose {
220249
// Verbose format: author and timestamp on first line, message on second line
221250
let datetime = DateTime::from_timestamp_millis(commit.created_at as i64)
222251
.unwrap_or_else(|| Utc.timestamp_millis_opt(0).unwrap());
223252
let formatted_time = datetime.format("%Y-%m-%d %H:%M:%S");
224253

225254
println!(
226-
"● {}{} {} {} {} {}",
255+
"● {}{} {} {} {} {} {}",
227256
&commit.id.to_string()[..2].blue().underline(),
228-
&commit.id.to_string()[2..7].blue(),
229-
conflicted_str,
230-
commit.author.name.dimmed(),
257+
&commit.id.to_string()[2..7].dimmed(),
258+
commit.author.name,
231259
formatted_time.to_string().dimmed(),
260+
no_changes,
261+
conflicted_str,
232262
mark.unwrap_or_default()
233263
);
234-
println!(
235-
"│ {}",
236-
commit
237-
.message
238-
.to_string()
239-
.replace('\n', " ")
240-
.chars()
241-
.take(100)
242-
.collect::<String>()
243-
);
264+
println!("│ {message}");
244265
} else {
245266
// Original format: everything on one line
246267
println!(
247-
"● {}{} {} {} {}",
268+
"● {}{} {} {} {} {}",
248269
&commit.id.to_string()[..2].blue().underline(),
249-
&commit.id.to_string()[2..7].blue(),
270+
&commit.id.to_string()[2..7].dimmed(),
271+
message,
272+
no_changes,
250273
conflicted_str,
251-
commit
252-
.message
253-
.to_string()
254-
.replace('\n', " ")
255-
.chars()
256-
.take(50)
257-
.collect::<String>(),
258274
mark.unwrap_or_default()
259275
);
260276
}
261277
if show_files {
262-
let commit_details =
263-
but_api::diff::commit_details(project.id, commit.id.into())?;
264278
for change in &commit_details.changes.changes {
265279
let cid = CliId::committed_file(&change.path.to_string(), commit.id)
266280
.to_string()
267281
.blue()
268282
.underline();
269283
let path = path_with_color(&change.status, change.path.to_string());
270284
let status_letter = status_letter(&change.status);
271-
println!("│ {cid} {path} {status_letter}");
272-
}
273-
if commit_details.changes.changes.is_empty() {
274-
println!("│ {}", "(no changes)".dimmed().italic());
285+
println!("│ {cid} {status_letter} {path}");
275286
}
276287
}
277288
}
278-
if branch.commits.is_empty() {
279-
println!("│ {}", "(no commits)".dimmed().italic());
280-
}
281289
}
282290
} else {
283291
let id = CliId::Unassigned.to_string().underline().blue();
284292
println!(
285-
"╭ {} [{}] {}",
293+
"╭┄{} [{}] {}",
286294
id,
287-
"UNASSIGNED".to_string().green().bold(),
295+
"Unassigned Changes".to_string().green().bold(),
288296
stack_mark.clone().unwrap_or_default()
289297
);
290298
print_assignments(&assignments, changes);

0 commit comments

Comments
 (0)