spacehub

surshar / claude-code

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.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / tests / git.test.ts
55 lines · 1.6 KBRaw
1import { describe, expect, mock, test, tier } from 'claude-code/testing'
2
3import Fixtures from './fixtures'
4
5tier('builtin')
6
7describe('git', () => {
8 test('each git child runs pinned to /work, in C locale', async ($, on) => {
9 const world = Fixtures.inRepository(on)
10
11 await $.session.start(Fixtures.SESSION)
12 await $.command.run(Fixtures.DIFF)
13 await world.clock.advance(Fixtures.SETTLE_MS)
14
15 const [discovery, ...pinned] = world.runs
16
17 expect(discovery?.argv).toContain('--show-toplevel')
18 expect(discovery?.init?.cwd).toBeUndefined()
19 expect(pinned.length).toBeGreaterThan(0)
20
21 for (const run of pinned) {
22 expect(run.argv.slice(0, 3)).toEqual([
23 'git',
24 '--git-dir=/work/.git',
25 '--work-tree=/work',
26 ])
27
28 expect(run.init).toMatchObject({ cwd: '/work', env: { LC_ALL: 'C' } })
29 }
30 })
31
32 test('a file moved in since the start is session work', async ($, on) => {
33 const clock = Fixtures.startsSession(on, Fixtures.SETTLE_MS)
34
35 on('process.run', ($, e) => ({
36 value: Fixtures.gitIn(e.argv, Fixtures.MOVED_IN),
37 }))
38
39 on('ui.open', () => ({ value: undefined }))
40 on('ui.invalidate', () => ({ value: undefined }))
41 on('session.messages', () => ({ value: [] }))
42 Fixtures.oldFiles(on)
43 mock.store(on)
44
45 await $.session.start(Fixtures.SESSION)
46 await $.command.run(Fixtures.DIFF)
47 await clock.advance(Fixtures.SETTLE_MS)
48
49 const drawn = Fixtures.textOf(await $.ui.render(Fixtures.PANE))
50
51 expect(drawn).toContain('1 file changed +1 -1')
52 expect(drawn).toContain('moved.ts')
53 expect(drawn).toContain('+1 file edited before this session (show)')
54 })
55})