|
| 1 | +import path from 'path'; |
1 | 2 | import { Action, Step } from '../../actions'; |
2 | 3 | import { spawnSync } from 'child_process'; |
| 4 | +import fs from 'fs'; |
3 | 5 |
|
4 | 6 | const exec = async (req: any, action: Action) => { |
5 | 7 | const step = new Step('writePack'); |
6 | 8 | try { |
7 | 9 | const cmd = `git receive-pack ${action.repoName}`; |
8 | 10 | step.log(`executing ${cmd}`); |
| 11 | + if (!action.proxyGitPath || !action.repoName) { |
| 12 | + throw new Error('proxyGitPath and repoName must be defined'); |
| 13 | + } |
| 14 | + const repoPath = path.join(action.proxyGitPath, action.repoName); |
9 | 15 |
|
| 16 | + const packDir = path.join(repoPath, '.git', 'objects', 'pack'); |
| 17 | + |
| 18 | + spawnSync('git', ['config', 'receive.unpackLimit', '0'], { |
| 19 | + cwd: repoPath, |
| 20 | + encoding: 'utf-8', |
| 21 | + }); |
| 22 | + const before = new Set(fs.readdirSync(packDir).filter((f) => f.endsWith('.idx'))); |
10 | 23 | const content = spawnSync('git', ['receive-pack', action.repoName], { |
11 | 24 | cwd: action.proxyGitPath, |
12 | 25 | input: req.body, |
13 | | - encoding: 'utf-8', |
14 | | - }).stdout; |
| 26 | + }); |
| 27 | + const after = new Set(fs.readdirSync(packDir).filter((f) => f.endsWith('.idx'))); |
| 28 | + |
| 29 | + const newIdxFiles = [...after].filter((f) => !before.has(f)); |
| 30 | + action.newIdxFiles = newIdxFiles; |
| 31 | + step.log(`.idx generati da questo push: ${newIdxFiles.join(', ') || '(nessuno)'}`); |
15 | 32 |
|
16 | | - step.log(content); |
17 | 33 | step.setContent(content); |
18 | 34 | } catch (e: any) { |
19 | 35 | step.setError(e.toString('utf-8')); |
|
0 commit comments