const cachePaths = [path.join(os.homedir(), '.cache', 'pre-commit')];
const py = getPythonVersion();
const cacheKey = `pre-commit-2-${hashString(py)}-${hashFile('.pre-commit-config.yaml')}`;
- await cache.restoreCache(cachePaths, cacheKey);
+ const restored = await cache.restoreCache(cachePaths, cacheKey);
const ret = await exec.exec('pre-commit', args, {ignoreReturnCode: push});
- await cache.saveCache(cachePaths, cacheKey);
+ if (!restored) {
+ await cache.saveCache(cachePaths, cacheKey);
+ }
if (ret && push) {
// actions do not run on pushes made by actions.
await exec.exec('git', ['commit', '-am', 'pre-commit fixes']);
const url = addToken(pr.head.repo.clone_url, token);
- await exec.exec('git', ['remote', 'set-url', 'origin', url]);
- await exec.exec('git', ['push', 'origin', 'HEAD']);
+ await exec.exec('git', ['push', url, 'HEAD']);
});
}
}