Skip to content

Commit aacf15f

Browse files
authored
Merge pull request #42 from collective/add-noDepth-shallow-clone-option
Added an option per repo to allow to shallow clone it with no deep
2 parents 1955f4c + 52a8ad8 commit aacf15f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Properties:
170170
- `tag`: Optional. Tag name.
171171
- `develop`: Optional. Boolean, can be toggled on/off to activate/deactivate a package. If activated, then deactivated afterwards, the package gets removed from `jsconfig` maintaining the synchronization with `mrs.developer.json`. Default is `true`.
172172
- `output`: Optional. Output directory override per repository.
173+
- `filterBlobs`: Optional. Used together with `tag` or `branch`, it creates a partial clone defaulting to the tag or branch specified. This partial clone won't clone the whole repository, but only the tag or branch specified.
173174

174175
## Usage with (non-TypeScript) React
175176

src/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ function getDefaultBranch(repository) {
4040
.then((result) => result.replace('origin/', ''));
4141
}
4242

43-
function cloneRepository(name, path, url, fetchUrl) {
43+
function cloneRepository(name, path, url, fetchUrl, options = {}) {
4444
console.log(`Cloning ${name} from ${fetchUrl || url}...`);
45+
const { filterBlobs, tag, branch } = options;
46+
const cloneOptions =
47+
filterBlobs && (tag || branch)
48+
? ['-b', tag || branch, '--filter=blob:none']
49+
: undefined;
4550
return gitP()
46-
.clone(getRemotePath(fetchUrl || url), path)
51+
.clone(getRemotePath(fetchUrl || url), path, cloneOptions)
4752
.then(() => {
4853
if (fetchUrl) {
4954
return gitP(path).remote([
@@ -215,7 +220,7 @@ function checkoutRepository(name, root, settings, options) {
215220
fetchUrl = settings.https;
216221
}
217222
const promise = !fs.existsSync(pathToRepo)
218-
? cloneRepository(name, pathToRepo, url, fetchUrl)
223+
? cloneRepository(name, pathToRepo, url, fetchUrl, settings)
219224
: openRepository(name, pathToRepo);
220225
return promise.then((git) => {
221226
if (git) {

test/cloneRepositoryTest.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ describe('cloneRepository', () => {
2121
expect(exists).to.be.true;
2222
});
2323

24+
it('puts the repository in ./src/develop with a partial (noDeep) clone', async () => {
25+
const repo = await developer
26+
.cloneRepository('repo1', './test/src/develop/repo1', './test/fake-remote/repo1', null, { filterBlobs: true, tag: '1.0.0' });
27+
28+
const branches = await repo.branchLocal();
29+
expect(branches.all[0]).to.be.equals('(no');
30+
});
31+
2432
it('gets the repository remotes', async () => {
2533
const repo = await developer.cloneRepository('repo1', './test/src/develop/repo1', './test/fake-remote/repo1');
2634
const remotes = await repo.getRemotes();

0 commit comments

Comments
 (0)