Skip to content

Commit c0a8996

Browse files
committed
move truncation
1 parent c5c1fe9 commit c0a8996

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

asyncgit/src/sync/hooks.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,7 @@ impl From<git2_hooks::HookResult> for HookResult {
2121
stdout,
2222
stderr,
2323
..
24-
} => {
25-
let mut combined = format!("{stdout}{stderr}");
26-
27-
if cfg!(windows) {
28-
const ANSI_CLEAR: &str = "\x1B[H\x1B[2J\x1B[3J";
29-
30-
if let Some(trimmed) =
31-
combined.strip_suffix(ANSI_CLEAR)
32-
{
33-
combined.truncate(trimmed.len());
34-
}
35-
}
36-
37-
Self::NotOk(combined)
38-
}
24+
} => Self::NotOk(format!("{stdout}{stderr}")),
3925
}
4026
}
4127
}

git2-hooks/src/hookspath.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,23 @@ impl HookPaths {
134134
if output.status.success() {
135135
Ok(HookResult::Ok { hook })
136136
} else {
137-
let stderr =
137+
let mut stderr =
138138
String::from_utf8_lossy(&output.stderr).to_string();
139-
let stdout =
139+
let mut stdout =
140140
String::from_utf8_lossy(&output.stdout).to_string();
141141

142+
if cfg!(windows) {
143+
const ANSI_CLEAR: &str = "\x1B[H\x1B[2J\x1B[3J";
144+
145+
for text in [&mut stderr, &mut stdout] {
146+
if let Some(trimmed) =
147+
text.strip_suffix(ANSI_CLEAR)
148+
{
149+
text.truncate(trimmed.len());
150+
}
151+
}
152+
}
153+
142154
Ok(HookResult::RunNotSuccessful {
143155
code: output.status.code(),
144156
stdout,

0 commit comments

Comments
 (0)