Skip to content

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

TypeScript

fix(diff): preserve hunks when Git forces colored output

7487453620980b70
diff --git a/mods/diff/hooks/git/argv/diff-leading-args.ts b/mods/diff/hooks/git/argv/diff-leading-args.ts
index fe77659e..b24d99a2 100644
--- a/mods/diff/hooks/git/argv/diff-leading-args.ts
+++ b/mods/diff/hooks/git/argv/diff-leading-args.ts
@@ -13,6 +13,7 @@ export const DIFF_LEADING_ARGS = [
'-c',
'core.quotePath=false',
'diff',
+ '--no-color',
'--no-ext-diff',
'--no-textconv',
'--ignore-submodules=dirty',
diff --git a/mods/diff/tests/git/fetch-diff.test.ts b/mods/diff/tests/git/fetch-diff.test.ts
index b9cb7bbe..a52a530d 100644
--- a/mods/diff/tests/git/fetch-diff.test.ts
+++ b/mods/diff/tests/git/fetch-diff.test.ts
@@ -148,6 +148,42 @@ describe('fetch-diff', () => {
).toBe(true)
})
+ test("forced git colors do not hide a changed file's hunks", async () => {
+ const deps = depsOf({
+ 'HEAD --shortstat': Fixtures.ok(
+ ' 1 file changed, 1 insertion(+), 1 deletion(-)',
+ ),
+ 'HEAD --numstat': Fixtures.ok('1\t1\ta.ts\0'),
+ 'ls-files': Fixtures.ok(),
+ })
+
+ const git = Fixtures.scriptedGitOf({
+ '--no-color': Fixtures.ok('@@ -1 +1 @@\n-old\n+new\n'),
+ diff: Fixtures.ok(
+ '\x1b[36m@@ -1 +1 @@\x1b[m\n\x1b[31m-old\x1b[m\n' +
+ '\x1b[32m+\x1b[m\x1b[32mnew\x1b[m\n',
+ ),
+ })
+
+ const outcome = await Git.fetchDiff(deps, 'uncommitted')
+ const data = outcome.kind === 'data' ? outcome.data : null
+ const [row] = data?.files ?? []
+
+ expect(data?.stats).toEqual({
+ filesCount: 1,
+ linesAdded: 1,
+ linesRemoved: 1,
+ })
+
+ expect(
+ data && row ? await Git.fetchFileHunks(git.run, data, row) : null,
+ ).toEqual({
+ hunks: [{ oldStart: 1, newStart: 1, lines: ['-old', '+new'] }],
+ isTruncated: false,
+ isLarge: false,
+ })
+ })
+
test('uncommitted mode drops pre-session untracked files', async () => {
const outcome = await Git.fetchDiff(
depsOf(