Skip to content

Commit e91dee5

Browse files
vsumnerKuSh
authored andcommitted
fix(git): drop state-hint extraction in compact status
KuSh: the in-progress state line ("rebase in progress", "merge in progress. unresolved conflicts", etc.) is enough — LLMs know which git commands resolve each state, so the per-state hint list was noise. Removes STATE_HINTS and extract_state_hint, and reduces extract_state_header to a short walk that returns the first detected state summary or None. Existing per-state tests now assert the exact compact summary.
1 parent 316e65e commit e91dee5

1 file changed

Lines changed: 10 additions & 88 deletions

File tree

src/cmds/git/git.rs

Lines changed: 10 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -820,30 +820,6 @@ fn detect_status_state(line: &str) -> Option<GitStatusState> {
820820
}
821821
}
822822

823-
const STATE_HINTS: &[&str] = &[
824-
"git commit --amend",
825-
"git rebase --continue",
826-
"git rebase --abort",
827-
"git rebase --skip",
828-
"git cherry-pick --continue",
829-
"git cherry-pick --abort",
830-
"git cherry-pick --skip",
831-
"git revert --continue",
832-
"git revert --abort",
833-
"git revert --skip",
834-
"git bisect reset",
835-
"git merge --abort",
836-
"git am --continue",
837-
"git am --abort",
838-
];
839-
840-
fn extract_state_hint(line: &str) -> Option<&'static str> {
841-
STATE_HINTS
842-
.iter()
843-
.find(|hint| line.contains(*hint))
844-
.copied()
845-
}
846-
847823
/// Extract a compact in-progress state summary from plain `git status` output.
848824
///
849825
/// Compact mode runs `git status --porcelain -b`, which omits the state header
@@ -868,48 +844,19 @@ fn extract_state_header(raw: &str) -> Option<String> {
868844
"nothing added to commit",
869845
];
870846

871-
let mut state = None;
872-
let mut hints: Vec<&'static str> = Vec::new();
873-
874847
for line in raw.lines() {
875848
let stripped = line.trim();
876849

877850
if STOPPERS.iter().any(|s| stripped.starts_with(s)) {
878851
break;
879852
}
880853

881-
// Branch header is already rendered from porcelain output.
882-
if stripped.starts_with("On branch ")
883-
|| stripped.starts_with("HEAD detached")
884-
|| stripped.starts_with("Your branch ")
885-
{
886-
continue;
887-
}
888-
889-
// Generic non-state hints — these are noise in normal status and
890-
// never appear inside a state block.
891-
if stripped.starts_with("(use \"git add")
892-
|| stripped.starts_with("(use \"git restore")
893-
{
894-
continue;
895-
}
896-
897-
if state.is_none() {
898-
state = detect_status_state(stripped);
899-
}
900-
901-
if let Some(hint) = extract_state_hint(stripped) {
902-
if !hints.contains(&hint) {
903-
hints.push(hint);
904-
}
854+
if let Some(state) = detect_status_state(stripped) {
855+
return Some(state.summary().to_string());
905856
}
906857
}
907858

908-
let state = state?;
909-
let mut out = vec![state.summary().to_string()];
910-
out.extend(hints.into_iter().map(String::from));
911-
912-
Some(out.join("\n"))
859+
None
913860
}
914861

915862
/// Minimal filtering for git status with user-provided args
@@ -2231,74 +2178,49 @@ mod tests {
22312178
fn test_extract_state_header_editing_while_rebasing() {
22322179
let raw = "On branch feature\n\ninteractive rebase in progress; onto abc1234\nLast command done (1 command done):\n edit abc123 some message\nNo commands remaining.\nYou are currently editing a commit while rebasing branch 'feature' on 'abc1234'.\n (use \"git commit --amend\" to amend the current commit)\n (use \"git rebase --continue\" once you are satisfied with your changes)\n\nnothing to commit, working tree clean\n";
22332180
let out = extract_state_header(raw).expect("state expected");
2234-
assert!(out.contains("rebase in progress"));
2235-
assert!(out.contains("git rebase --continue"));
2236-
assert!(out.contains("git commit --amend"));
2237-
assert!(!out.contains("interactive rebase in progress"));
2238-
assert!(!out.contains("Last command done"));
2181+
assert_eq!(out, "rebase in progress");
22392182
}
22402183

22412184
#[test]
22422185
fn test_extract_state_header_merge_unresolved() {
22432186
let raw = "On branch main\nYou have unmerged paths.\n (fix conflicts and run \"git commit\")\n (use \"git merge --abort\" to abort the merge)\n\nUnmerged paths:\n\tboth modified: src/main.rs\n";
22442187
let out = extract_state_header(raw).expect("state expected");
2245-
assert!(out.contains("merge in progress. unresolved conflicts"));
2246-
assert!(out.contains("git merge --abort"));
2247-
assert!(!out.contains("git commit"));
2188+
assert_eq!(out, "merge in progress. unresolved conflicts");
22482189
}
22492190

22502191
#[test]
22512192
fn test_extract_state_header_cherry_pick() {
22522193
let raw = "On branch main\n\nYou are currently cherry-picking commit abc1234.\n (fix conflicts and run \"git cherry-pick --continue\")\n (use \"git cherry-pick --abort\" to cancel the cherry-pick operation)\n\nnothing to commit, working tree clean\n";
22532194
let out = extract_state_header(raw).expect("state expected");
2254-
assert!(out.contains("cherry-pick in progress"));
2255-
assert!(out.contains("git cherry-pick --continue"));
2256-
assert!(out.contains("git cherry-pick --abort"));
2195+
assert_eq!(out, "cherry-pick in progress");
22572196
}
22582197

22592198
#[test]
22602199
fn test_extract_state_header_bisect() {
22612200
let raw = "On branch main\n\nYou are currently bisecting, started from branch 'main'.\n (use \"git bisect reset\" to get back to the original branch)\n\nnothing to commit, working tree clean\n";
22622201
let out = extract_state_header(raw).expect("state expected");
2263-
assert!(out.contains("bisect in progress"));
2264-
assert!(out.contains("git bisect reset"));
2202+
assert_eq!(out, "bisect in progress");
22652203
}
22662204

22672205
#[test]
22682206
fn test_extract_state_header_revert() {
22692207
let raw = "On branch main\n\nYou are currently reverting commit abc1234.\n (fix conflicts and run \"git revert --continue\")\n (use \"git revert --abort\" to cancel the revert operation)\n\nnothing to commit, working tree clean\n";
22702208
let out = extract_state_header(raw).expect("state expected");
2271-
assert!(out.contains("revert in progress"));
2272-
assert!(out.contains("git revert --continue"));
2209+
assert_eq!(out, "revert in progress");
22732210
}
22742211

22752212
#[test]
22762213
fn test_extract_state_header_merge_in_middle() {
22772214
let raw = "On branch main\n\nAll conflicts fixed but you are still merging.\n (use \"git commit\" to conclude merge)\n\nChanges to be committed:\n\tmodified: src/main.rs\n";
22782215
let out = extract_state_header(raw).expect("state expected");
2279-
assert!(out.contains("merge in progress. no conflicts"));
2280-
assert!(!out.contains("git commit"));
2281-
}
2282-
2283-
#[test]
2284-
fn test_extract_state_header_drops_generic_add_hints() {
2285-
// `(use "git add ...)` is generic status hint noise. Confirm that
2286-
// when we're inside a state block, it's still skipped but the state
2287-
// itself survives.
2288-
let raw = "On branch main\n\nYou are currently rebasing branch 'foo' on 'bar'.\n (use \"git add <file>...\" to mark resolution)\n (use \"git rebase --continue\" once done)\n\nnothing to commit, working tree clean\n";
2289-
let out = extract_state_header(raw).expect("state expected");
2290-
assert!(out.contains("rebase in progress"));
2291-
assert!(out.contains("git rebase --continue"));
2292-
assert!(!out.contains("git add <file>"));
2216+
assert_eq!(out, "merge in progress. no conflicts");
22932217
}
22942218

22952219
#[test]
22962220
fn test_extract_state_header_am_session() {
22972221
let raw = "On branch main\n\nYou are in the middle of an am session.\n (use \"git am --continue\" to continue)\n (use \"git am --abort\" to restore the original branch)\n\nnothing to commit, working tree clean\n";
22982222
let out = extract_state_header(raw).expect("state expected");
2299-
assert!(out.contains("am session in progress"));
2300-
assert!(out.contains("git am --continue"));
2301-
assert!(out.contains("git am --abort"));
2223+
assert_eq!(out, "am session in progress");
23022224
}
23032225

23042226
#[test]

0 commit comments

Comments
 (0)