From df39f78d20d82ec8ab20a01b152ebdbd16a12986 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 30 Sep 2025 12:45:00 -0500 Subject: [PATCH] Fix "git pull" listing changed files --- src/lib/commands/git/pull.test.ts | 39 +++++++++++++++++++++++++++++++ src/lib/commands/git/pull.ts | 14 +++++++---- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/lib/commands/git/pull.test.ts b/src/lib/commands/git/pull.test.ts index d4273608..1e47b6e7 100644 --- a/src/lib/commands/git/pull.test.ts +++ b/src/lib/commands/git/pull.test.ts @@ -81,4 +81,43 @@ describe('GitPullCommand', () => { }); }); }); + + describe('execute', () => { + it('should list modified files when there are uncommitted changes', async () => { + // Mock statusMatrix to return some modified files + const mockGitWithChanges = { + ...mockGit, + statusMatrix: async () => [ + ['src/index.ts', 1, 2, 1], // Modified file + ['README.md', 1, 2, 2], // Modified and staged + ['package.json', 0, 2, 0], // Untracked file + ], + } as unknown as Git; + + // Mock FS to ensure .git directory exists + const mockFSWithGit = { + stat: async (path: string) => { + if (path.endsWith('/.git')) { + return { isDirectory: () => true }; + } + throw new Error('File not found'); + }, + } as unknown as JSRuntimeFS; + + const commandWithChanges = new GitPullCommand({ + git: mockGitWithChanges, + fs: mockFSWithGit, + pwd: '/test/repo', + }); + + const result = await commandWithChanges.execute(['origin', 'main']); + + expect(result.exitCode).toBe(1); + expect(result.stderr).toContain('error: Your local changes to the following files would be overwritten by merge:'); + expect(result.stderr).toContain('\tsrc/index.ts'); + expect(result.stderr).toContain('\tREADME.md'); + expect(result.stderr).toContain('\tpackage.json'); + expect(result.stderr).toContain('Please commit your changes or stash them before you merge.'); + }); + }); }); \ No newline at end of file diff --git a/src/lib/commands/git/pull.ts b/src/lib/commands/git/pull.ts index deee289f..0bf813aa 100644 --- a/src/lib/commands/git/pull.ts +++ b/src/lib/commands/git/pull.ts @@ -69,12 +69,16 @@ export class GitPullCommand implements GitSubcommand { dir: this.pwd, }); - const hasChanges = statusMatrix.some(([, headStatus, workdirStatus, stageStatus]) => { - return headStatus !== workdirStatus || headStatus !== stageStatus; - }); + const modifiedFiles = statusMatrix + .filter(([, headStatus, workdirStatus, stageStatus]) => { + // Check for any uncommitted changes (modified, staged, or untracked) + return headStatus !== workdirStatus || headStatus !== stageStatus; + }) + .map(([filepath]) => filepath); - if (hasChanges) { - return createErrorResult('error: Your local changes to the following files would be overwritten by merge:\nPlease commit your changes or stash them before you merge.'); + if (modifiedFiles.length > 0) { + const fileList = modifiedFiles.map(file => `\t${file}`).join('\n'); + return createErrorResult(`error: Your local changes to the following files would be overwritten by merge:\n${fileList}\nPlease commit your changes or stash them before you merge.`); } try {