Skip to content

Commit

Permalink
feat(git): repo is copied while filtering file with gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjaouen committed Dec 27, 2024
1 parent a46c12b commit a4ffd3e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/core/git/Git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import SFPLogger, { Logger, LoggerLevel } from '@flxbl-io/sfp-logger';
import simplegit, { SimpleGit } from 'simple-git';
import fs = require('fs-extra');
import path = require('path');
import ignore from 'ignore';
import GitIdentity from './GitIdentity';
const tmp = require('tmp');

Expand Down Expand Up @@ -134,8 +136,21 @@ export default class Git {
SFPLogger.log(`Copying the repository to ${locationOfCopiedDirectory.name}`, LoggerLevel.INFO, logger);
let repoDir = locationOfCopiedDirectory.name;

// Copy source directory to temp dir
fs.copySync(process.cwd(), repoDir);
// Read .gitignore file
const gitignore = ignore();
const gitignorePath = `${process.cwd()}/.gitignore`;
if (fs.existsSync(gitignorePath)) {
const gitignoreContent = fs.readFileSync(gitignorePath).toString();
gitignore.add(gitignoreContent);
}

// Copy source directory to temp dir respecting .gitignore
fs.copySync(process.cwd(), repoDir, {
filter: (src) => {
const relativePath = path.relative(process.cwd(), src);
return !relativePath || !gitignore.ignores(relativePath);
}
});

//Initiate git on new repo on using the abstracted object
let git = new Git(repoDir, logger);
Expand Down Expand Up @@ -172,7 +187,7 @@ export default class Git {

public raw(commands: string[]) {
return this._git.raw(commands);
}
}

public getRepositoryPath() {
return this.repositoryLocation;
Expand Down

0 comments on commit a4ffd3e

Please sign in to comment.