Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/proxy/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const pushActionChain = [
proc.push.pullRemote,
proc.push.writePack,
proc.push.getDiff,
proc.push.clearBareClone,
proc.push.scanDiff,
proc.push.blockForAuth,
];
Expand Down
20 changes: 20 additions & 0 deletions src/proxy/processors/push-action/clearBareClone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const Step = require('../../actions').Step;
const fs = require('node:fs');

const exec = async (req, action) => {
const step = new Step('clearBareClone');

// Recursively remove the contents of ./.remote and ignore exceptions
fs.rm('./.remote', { recursive: true, force: true }, (err) => {
if (err) {
throw err;
}
console.log(`.remote is deleted!`);
});

action.addStep(step);
return action;
};

exec.displayName = 'clearBareClone.exec';
exports.exec = exec;
1 change: 1 addition & 0 deletions src/proxy/processors/push-action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ exports.checkIfWaitingAuth = require('./checkIfWaitingAuth').exec;
exports.checkCommitMessages = require('./checkCommitMessages').exec;
exports.checkAuthorEmails = require('./checkAuthorEmails').exec;
exports.checkUserPushPermission = require('./checkUserPushPermission').exec;
exports.clearBareClone = require('./clearBareClone').exec;
26 changes: 26 additions & 0 deletions test/testClearBareClone.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require('fs');
const chai = require('chai');
const clearBareClone = require('../src/proxy/processors/push-action/clearBareClone').exec;
const pullRemote = require('../src/proxy/processors/push-action/pullRemote').exec;
const { Action } = require('../src/proxy/actions/Action');
chai.should();

const expect = chai.expect;
const timestamp = Date.now();

describe('clear bare and local clones', async () => {
it('pull remote generates a local .remote folder', async () => {
const action = new Action('123', 'type', 'get', timestamp, 'finos/git-proxy');
action.url = 'https://github.com/finos/git-proxy';
await pullRemote({}, action);

expect(fs.existsSync(`./.remote/${timestamp}`)).to.be.true;
});

it('clear bare clone function purges .remote folder and specific clone folder', async () => {
const action = new Action('123', 'type', 'get', timestamp, 'finos/git-proxy');
await clearBareClone(null, action);
expect(fs.existsSync(`./.remote`)).to.throw;
expect(fs.existsSync(`./.remote/${timestamp}`)).to.throw;
});
});