Skip to content

Commit 9952bb6

Browse files
authored
fix: Only add explicit paths to git staging (#7)
1 parent cabb913 commit 9952bb6

3 files changed

Lines changed: 5 additions & 42 deletions

File tree

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/file-collector.test.ts

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe('collectFiles', () => {
178178
});
179179

180180
describe('no paths specified', () => {
181-
it('should collect all changed files using git add .', async () => {
181+
it('should not collect changed files using git add .', async () => {
182182
const testDir = path.join(process.cwd(), 'test-all-changes-temp');
183183

184184
try {
@@ -196,15 +196,10 @@ describe('collectFiles', () => {
196196
fs.writeFileSync(path.join(testDir, 'existing.txt'), 'modified');
197197
fs.writeFileSync(path.join(testDir, 'new.txt'), 'new content');
198198

199-
// Call without paths - should add all changes
199+
// Call without paths - should not add all changes
200200
const result = await collectFiles(undefined, testDir);
201201

202-
assert.strictEqual(result.length, 2);
203-
assert.ok(result.some((f) => f.path === 'existing.txt'));
204-
assert.ok(result.some((f) => f.path === 'new.txt'));
205-
206-
const modifiedFile = result.find((f) => f.path === 'existing.txt');
207-
assert.strictEqual(modifiedFile?.content, 'modified');
202+
assert.strictEqual(result.length, 0);
208203
} finally {
209204
if (fs.existsSync(testDir)) {
210205
fs.rmSync(testDir, { recursive: true, force: true });
@@ -236,36 +231,6 @@ describe('collectFiles', () => {
236231
}
237232
}
238233
});
239-
240-
it('should handle renamed files correctly', async () => {
241-
const testDir = path.join(process.cwd(), 'test-rename-temp');
242-
243-
try {
244-
fs.mkdirSync(testDir, { recursive: true });
245-
initGitRepo(testDir);
246-
247-
const { execSync } = require('node:child_process');
248-
249-
// Create and commit initial file
250-
fs.writeFileSync(path.join(testDir, 'old-name.txt'), 'content');
251-
execSync('git add old-name.txt', { cwd: testDir, stdio: 'ignore' });
252-
execSync('git commit -m "initial"', { cwd: testDir, stdio: 'ignore' });
253-
254-
// Rename file
255-
fs.renameSync(path.join(testDir, 'old-name.txt'), path.join(testDir, 'new-name.txt'));
256-
257-
// Call without paths - should handle rename
258-
const result = await collectFiles(undefined, testDir);
259-
260-
// Git stages both the deletion and addition
261-
assert.ok(result.length >= 1);
262-
assert.ok(result.some((f) => f.path === 'new-name.txt'));
263-
} finally {
264-
if (fs.existsSync(testDir)) {
265-
fs.rmSync(testDir, { recursive: true, force: true });
266-
}
267-
}
268-
});
269234
});
270235

271236
describe('specific paths', () => {

src/file-collector.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ async function addFilesToGit(paths: string[] | undefined, workingDirectory: stri
3535
args.push(...paths);
3636
core.debug(`Adding ${paths.length} path(s) to git staging area`);
3737
} else {
38-
// Add all changes
39-
args.push('.');
40-
core.debug('Adding all changes to git staging area');
38+
return;
4139
}
4240

4341
let errorOutput = '';

0 commit comments

Comments
 (0)