diff --git a/src/cli/replicate.ts b/src/cli/replicate.ts index 4bacc3b..e5d5b5e 100644 --- a/src/cli/replicate.ts +++ b/src/cli/replicate.ts @@ -28,6 +28,16 @@ export default class Replicate extends Command { patchHook: flags.string({ description: 'node.js file to patch the patches', }), + excludePath: flags.string({ + description: + 'files to exclude when applying a patch (as in git apply --exclude, but always after includes)', + multiple: true, + }), + includePath: flags.string({ + description: + 'files to include when applying a patch (as in git apply --include, but always before excludes)', + multiple: true, + }), }; static args = [ @@ -49,7 +59,15 @@ export default class Replicate extends Command { const proj = getProjectConfig(); - const { destBranch, doNotCommit, remote, targetBranch, patchHook } = { ...proj, ...flags }; + const { + destBranch, + doNotCommit, + remote, + targetBranch, + patchHook, + includePath: includePaths, + excludePath: excludePaths, + } = { ...proj, ...flags }; const { source, dest } = { ...proj, @@ -97,6 +115,8 @@ export default class Replicate extends Command { patchHook, remote, targetBranch, + includePaths, + excludePaths, }); if (repl === true) { // patches got applied to the branch, without pushing and creating a MR (due to --doNotCommit) diff --git a/src/copykitku.ts b/src/copykitku.ts index 92c8cfd..750607d 100644 --- a/src/copykitku.ts +++ b/src/copykitku.ts @@ -65,16 +65,28 @@ export default class Copykitku { patchHook?: string | null; remote: string; targetBranch: string; + includePaths?: string[]; + excludePaths?: string[]; }, ) { const destBranch = opts.destBranch || `${sourceMR.repo.owner.username}/${sourceMR.repo.name}/mr-${sourceMR.id}`; - const { doNotCommit, doNotPush, remote, targetBranch, patchHook } = opts; + const { + doNotCommit, + doNotPush, + remote, + targetBranch, + patchHook, + includePaths, + excludePaths, + } = opts; await this.replicateCommits(sourceMR.commits, destination, { destBranch, doNotCommit, patchHook, + includePaths, + excludePaths, }); if (doNotCommit !== true && doNotPush !== true) { @@ -100,9 +112,11 @@ export default class Copykitku { destBranch: string; doNotCommit?: boolean | null; patchHook?: string | null; + includePaths?: string[]; + excludePaths?: string[]; }, ) { - const { destBranch, doNotCommit, patchHook } = opts; + const { destBranch, doNotCommit, patchHook, includePaths, excludePaths } = opts; const commits = Array.isArray(sourceCommit) ? sourceCommit : [sourceCommit]; const patchHookCall = patchHook @@ -152,7 +166,13 @@ export default class Copykitku { for (let i = 0; i < patchFiles.length; i += 1) { const patch = patchFiles[i]; - await git.applyPatch(patch.patchFile, ['--index']); + await git.applyPatch( + patch.patchFile, + ['--index'].concat( + ...(includePaths || []).map((inc) => ['--include', inc]), + ...(excludePaths || []).map((inc) => ['--exclude', inc]), + ), + ); if (doNotCommit !== true) { await git.commit(patch.title + (patch.content ? '\n\n' + patch.content : ''), { '--author': patch.from,