Skip to content

Commit

Permalink
feat(migrate): switch to git-filter-repo and use temp folder outside …
Browse files Browse the repository at this point in the history
…of source repo
  • Loading branch information
rikkit committed Feb 21, 2022
1 parent 7042eee commit 7564b76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions bin/meta-project-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const run = ({ process }) => {

const destArg = argv[2] === 'blank' ? argv[3] : argv[2];
const repoUrl = argv[3] === 'blank' ? argv[4] : argv[3];
const branch = argv[4] === 'blank' ? null : argv[4];
const branch = (argv[4] === 'blank' ? null : argv[4]) || "master";
(destArg && repoUrl) || usage();

// Load the ".meta" module.
Expand Down Expand Up @@ -93,42 +93,42 @@ const run = ({ process }) => {
console.log(`Root remote found: ${cyan(tildify(rootRepo))}`);

const monorepoDir = process.cwd();
const tempDir = path.resolve(monorepoDir, './.tmp');
console.log({ tempDir });
mkdirp.sync(tempDir);
const tempDir = fs.mkdtempSync("meta-project-migrate-");
console.log(tempDir);

function afterGitClone(err) {
if (err) throw err;

console.log(`Splitting subdirectory "${dest}" history into temporary folder "${tempDir}"`);
splitSubtree({
subdirectory: dest,
source: monorepoDir,
target: tempDir,
branch: branch,
});

process.chdir(tempDir);

console.log(`Now working in ${tempDir}`);

console.log(`Removing original remote "origin"`);

removeRemote({
remoteName: 'origin',
});

console.log(`Splitting subdirectory "${dest}" history`);

splitSubtree({
subdirectory: dest,
});


console.log(`Setting remote origin to ${repoUrl}`);

addRemote({
remoteName: 'origin',
gitUrl: repoUrl,
});

let pushBranch = branch || 'master';
console.log(`Pushing split history to new remote origin ${repoUrl} on branch ${pushBranch}`);
console.log(`Pushing split history to new remote origin ${repoUrl} on branch ${branch}`);

gitPush({
remote: 'origin',
branch: pushBranch,
branch: branch,
});

process.chdir(monorepoDir);
Expand Down
4 changes: 2 additions & 2 deletions lib/splitSubtree.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const childProcess = require('child_process');

function splitSubtree({ subdirectory, branch = 'master' }) {
function splitSubtree({ subdirectory, source, target, branch }) {
return childProcess
.execSync(`git filter-branch --prune-empty --subdirectory-filter ${subdirectory} ${branch}`)
.execSync(`git filter-repo --subdirectory-filter ${subdirectory} --refs ${branch} --source ${source} --target ${target}`)
.toString()
.trim();
}
Expand Down

0 comments on commit 7564b76

Please sign in to comment.