diff --git a/packages/git/src/diff.ts b/packages/git/src/diff.ts index b13a9f2..c7f7191 100644 --- a/packages/git/src/diff.ts +++ b/packages/git/src/diff.ts @@ -38,7 +38,11 @@ export function resolveDiffArgs(ref: string): RefDiffArgs { case 'work': return { type: 'args', args: ['HEAD'], includeUntracked: true }; default: - return { type: 'args', args: [normalizeRef(ref)], includeUntracked: true }; + // Bare refs (`diffity main`) diff against the working tree, so untracked + // files are part of the change set (#10). Ranges (`A..B`) pin both + // endpoints — the working tree isn't involved, so untracked files must + // be excluded or the diff won't match `git diff A..B`. + return { type: 'args', args: [normalizeRef(ref)], includeUntracked: !ref.includes('..') }; } } diff --git a/packages/git/tests/get-diff-files.test.ts b/packages/git/tests/get-diff-files.test.ts index ec3684d..0b1ad05 100644 --- a/packages/git/tests/get-diff-files.test.ts +++ b/packages/git/tests/get-diff-files.test.ts @@ -86,6 +86,28 @@ describe('getDiffFiles', () => { git('checkout -- base.txt'); }); + it('includes untracked files for bare refs (diff against working tree)', async () => { + const { getDiffFiles } = await import('../src/diff.js'); + writeFile('untracked-file.txt', 'untracked\n'); + + const files = getDiffFiles('main'); + expect(files).toContain('untracked-file.txt'); + + execSync(`rm "${join(repoDir, 'untracked-file.txt')}"`, { stdio: 'pipe' }); + }); + + it('excludes untracked files for range refs (both endpoints pinned)', async () => { + const { getDiffFiles } = await import('../src/diff.js'); + writeFile('untracked-file.txt', 'untracked\n'); + + const files = getDiffFiles('main..feature'); + expect(files).toContain('feature.txt'); + expect(files).toContain('base.txt'); + expect(files).not.toContain('untracked-file.txt'); + + execSync(`rm "${join(repoDir, 'untracked-file.txt')}"`, { stdio: 'pipe' }); + }); + it('returns working tree files for work ref', async () => { const { getDiffFiles } = await import('../src/diff.js'); writeFile('untracked-file.txt', 'untracked\n');