Skip to content

Commit 644c80b

Browse files
committed
But status now shows remote commits as well
1 parent d4403aa commit 644c80b

File tree

1 file changed

+111
-71
lines changed

1 file changed

+111
-71
lines changed

crates/but/src/status/mod.rs

Lines changed: 111 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -221,39 +221,24 @@ pub fn print_group(
221221
print_assignments(&assignments, changes, false);
222222
}
223223
first = false;
224+
for commit in &branch.upstream_commits {
225+
let dot = "●".yellow();
226+
print_commit(
227+
commit.id,
228+
commit.created_at as i64,
229+
commit.message.to_string(),
230+
commit.author.name.clone(),
231+
dot,
232+
project.id,
233+
false,
234+
show_files,
235+
verbose,
236+
false,
237+
)?;
238+
}
224239
for commit in &branch.commits {
225240
let marked =
226241
crate::mark::commit_marked(ctx, commit.id.to_string()).unwrap_or_default();
227-
let mark = if marked {
228-
Some("◀ Marked ▶".red().bold())
229-
} else {
230-
None
231-
};
232-
let conflicted_str = if commit.has_conflicts {
233-
"{conflicted}".red()
234-
} else {
235-
"".normal()
236-
};
237-
238-
let mut message = commit
239-
.message
240-
.to_string()
241-
.replace('\n', " ")
242-
.chars()
243-
.take(50)
244-
.collect::<String>()
245-
.normal();
246-
if message.is_empty() {
247-
message = "(no commit message)".to_string().dimmed().italic();
248-
}
249-
250-
let commit_details = but_api::diff::commit_details(project.id, commit.id.into())?;
251-
let no_changes = if show_files && commit_details.changes.changes.is_empty() {
252-
"(no changes)".dimmed().italic()
253-
} else {
254-
"".to_string().normal()
255-
};
256-
257242
let dot = match commit.state {
258243
but_workspace::ui::CommitState::LocalOnly => "●".normal(),
259244
but_workspace::ui::CommitState::LocalAndRemote(object_id) => {
@@ -265,47 +250,18 @@ pub fn print_group(
265250
}
266251
but_workspace::ui::CommitState::Integrated => "●".purple(),
267252
};
268-
269-
if verbose {
270-
// Verbose format: author and timestamp on first line, message on second line
271-
let datetime = DateTime::from_timestamp_millis(commit.created_at as i64)
272-
.unwrap_or_else(|| Utc.timestamp_millis_opt(0).unwrap());
273-
let formatted_time = datetime.format("%Y-%m-%d %H:%M:%S");
274-
275-
println!(
276-
"┊{dot} {}{} {} {} {} {} {}",
277-
&commit.id.to_string()[..2].blue().underline(),
278-
&commit.id.to_string()[2..7].dimmed(),
279-
commit.author.name,
280-
formatted_time.to_string().dimmed(),
281-
no_changes,
282-
conflicted_str,
283-
mark.unwrap_or_default()
284-
);
285-
println!("┊│ {message}");
286-
} else {
287-
// Original format: everything on one line
288-
println!(
289-
"┊{dot} {}{} {} {} {} {}",
290-
&commit.id.to_string()[..2].blue().underline(),
291-
&commit.id.to_string()[2..7].dimmed(),
292-
message,
293-
no_changes,
294-
conflicted_str,
295-
mark.unwrap_or_default()
296-
);
297-
}
298-
if show_files {
299-
for change in &commit_details.changes.changes {
300-
let cid = CliId::committed_file(&change.path.to_string(), commit.id)
301-
.to_string()
302-
.blue()
303-
.underline();
304-
let path = path_with_color(&change.status, change.path.to_string());
305-
let status_letter = status_letter(&change.status);
306-
println!("┊│ {cid} {status_letter} {path}");
307-
}
308-
}
253+
print_commit(
254+
commit.id,
255+
commit.created_at as i64,
256+
commit.message.to_string(),
257+
commit.author.name.clone(),
258+
dot,
259+
project.id,
260+
marked,
261+
show_files,
262+
verbose,
263+
commit.has_conflicts,
264+
)?;
309265
}
310266
}
311267
} else {
@@ -396,3 +352,87 @@ pub(crate) fn all_committed_files(ctx: &mut CommandContext) -> anyhow::Result<Ve
396352
}
397353
Ok(committed_files)
398354
}
355+
356+
#[expect(clippy::too_many_arguments)]
357+
fn print_commit(
358+
commit_id: gix::ObjectId,
359+
created_at: i64,
360+
message: String,
361+
author_name: String,
362+
dot: ColoredString,
363+
project_id: gitbutler_project::ProjectId,
364+
marked: bool,
365+
show_files: bool,
366+
verbose: bool,
367+
has_conflicts: bool,
368+
) -> anyhow::Result<()> {
369+
let mark = if marked {
370+
Some("◀ Marked ▶".red().bold())
371+
} else {
372+
None
373+
};
374+
let conflicted_str = if has_conflicts {
375+
"{conflicted}".red()
376+
} else {
377+
"".normal()
378+
};
379+
380+
let mut message = message
381+
.replace('\n', " ")
382+
.chars()
383+
.take(50)
384+
.collect::<String>()
385+
.normal();
386+
if message.is_empty() {
387+
message = "(no commit message)".to_string().dimmed().italic();
388+
}
389+
390+
let commit_details = but_api::diff::commit_details(project_id, commit_id.into())?;
391+
let no_changes = if show_files && commit_details.changes.changes.is_empty() {
392+
"(no changes)".dimmed().italic()
393+
} else {
394+
"".to_string().normal()
395+
};
396+
397+
if verbose {
398+
// Verbose format: author and timestamp on first line, message on second line
399+
let datetime = DateTime::from_timestamp_millis(created_at)
400+
.unwrap_or_else(|| Utc.timestamp_millis_opt(0).unwrap());
401+
let formatted_time = datetime.format("%Y-%m-%d %H:%M:%S");
402+
403+
println!(
404+
"┊{dot} {}{} {} {} {} {} {}",
405+
&commit_id.to_string()[..2].blue().underline(),
406+
&commit_id.to_string()[2..7].dimmed(),
407+
author_name,
408+
formatted_time.to_string().dimmed(),
409+
no_changes,
410+
conflicted_str,
411+
mark.unwrap_or_default()
412+
);
413+
println!("┊│ {message}");
414+
} else {
415+
// Original format: everything on one line
416+
println!(
417+
"┊{dot} {}{} {} {} {} {}",
418+
&commit_id.to_string()[..2].blue().underline(),
419+
&commit_id.to_string()[2..7].dimmed(),
420+
message,
421+
no_changes,
422+
conflicted_str,
423+
mark.unwrap_or_default()
424+
);
425+
}
426+
if show_files {
427+
for change in &commit_details.changes.changes {
428+
let cid = CliId::committed_file(&change.path.to_string(), commit_id)
429+
.to_string()
430+
.blue()
431+
.underline();
432+
let path = path_with_color(&change.status, change.path.to_string());
433+
let status_letter = status_letter(&change.status);
434+
println!("┊│ {cid} {status_letter} {path}");
435+
}
436+
}
437+
Ok(())
438+
}

0 commit comments

Comments
 (0)