Skip to content

Commit 21baf6f

Browse files
committed
feat: gix status now performs HEAD^{tree}-index comparisons as well.
1 parent 8fe6e86 commit 21baf6f

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

gitoxide-core/src/repository/status.rs

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::bail;
22
use gix::bstr::{BStr, BString, ByteSlice};
3-
use gix::status::index_worktree::Item;
3+
use gix::status::{self, index_worktree};
44
use gix_status::index_as_worktree::{Change, Conflict, EntryStatus};
55
use std::path::Path;
66

@@ -109,21 +109,53 @@ pub fn show(
109109
}
110110
None => gix::status::Submodule::AsConfigured { check_dirty: false },
111111
})
112-
.into_index_worktree_iter(pathspecs)?;
112+
.into_iter(pathspecs)?;
113113

114114
for item in iter.by_ref() {
115115
let item = item?;
116116
match item {
117-
Item::Modification {
117+
status::Item::TreeIndex(change) => {
118+
let (location, _, _, _) = change.fields();
119+
let status = match change {
120+
gix::diff::index::Change::Addition { .. } => "A",
121+
gix::diff::index::Change::Deletion { .. } => "D",
122+
gix::diff::index::Change::Modification { .. } => "M",
123+
gix::diff::index::Change::Rewrite {
124+
ref source_location, ..
125+
} => {
126+
let source_location = gix::path::from_bstr(source_location.as_ref());
127+
let source_location = gix::path::relativize_with_prefix(&source_location, prefix);
128+
writeln!(
129+
out,
130+
"{status: >2} {source_rela_path} → {dest_rela_path}",
131+
status = "R",
132+
source_rela_path = source_location.display(),
133+
dest_rela_path =
134+
gix::path::relativize_with_prefix(&gix::path::from_bstr(location), prefix).display(),
135+
)?;
136+
continue;
137+
}
138+
gix::diff::index::Change::Unmerged { .. } => {
139+
// TODO: should this be displayed? How to prevent double-display?
140+
continue;
141+
}
142+
};
143+
writeln!(
144+
out,
145+
"{status: >2} {rela_path}",
146+
rela_path = gix::path::relativize_with_prefix(&gix::path::from_bstr(location), prefix).display(),
147+
)?;
148+
}
149+
status::Item::IndexWorktree(index_worktree::Item::Modification {
118150
entry: _,
119151
entry_index: _,
120152
rela_path,
121153
status,
122-
} => print_index_entry_status(&mut out, prefix, rela_path.as_ref(), status)?,
123-
Item::DirectoryContents {
154+
}) => print_index_entry_status(&mut out, prefix, rela_path.as_ref(), status)?,
155+
status::Item::IndexWorktree(index_worktree::Item::DirectoryContents {
124156
entry,
125157
collapsed_directory_status,
126-
} => {
158+
}) => {
127159
if collapsed_directory_status.is_none() {
128160
writeln!(
129161
out,
@@ -139,12 +171,12 @@ pub fn show(
139171
)?;
140172
}
141173
}
142-
Item::Rewrite {
174+
status::Item::IndexWorktree(index_worktree::Item::Rewrite {
143175
source,
144176
dirwalk_entry,
145177
copy: _, // TODO: how to visualize copies?
146178
..
147-
} => {
179+
}) => {
148180
// TODO: handle multi-status characters, there can also be modifications at the same time as determined by their ID and potentially diffstats.
149181
writeln!(
150182
out,
@@ -175,9 +207,8 @@ pub fn show(
175207
writeln!(err, "{outcome:#?}", outcome = out.index_worktree).ok();
176208
}
177209

178-
writeln!(err, "\nhead -> index isn't implemented yet")?;
179-
progress.init(Some(out.index.entries().len()), gix::progress::count("files"));
180-
progress.set(out.index.entries().len());
210+
progress.init(Some(out.worktree_index.entries().len()), gix::progress::count("files"));
211+
progress.set(out.worktree_index.entries().len());
181212
progress.show_throughput(start);
182213
Ok(())
183214
}

0 commit comments

Comments
 (0)