Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalrymple committed Jul 21, 2017
1 parent 3a6b8e4 commit 0e88d1a
Showing 1 changed file with 43 additions and 38 deletions.
81 changes: 43 additions & 38 deletions lib/Hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,49 @@ function moveFiles(source, destination, files) {
function cloneMultipleAndMerge(fromRepos, combinedRepo) {
const mergedRepos = [];

return Promise.each(fromRepos, (fromRepo) => {
if (fromRepo.constructor !== String || fromRepo.constructor !== Object) {
throw new TypeError('Incorrect type of from parameter. Clone source in array is an invalid type. Must be an String or an Object');
}
for (repo of fromRepos) {
if (fromRepo.constructor !== String || fromRepo.constructor !== Object) {
throw new TypeError('Incorrect type of from parameter. Clone source in array is an invalid type. Must be an String or an Object');
}

let name = Path.basename(fromRepo);

if (mergedRepos.includes(name)) {
name += `-${ShortID.generate()}`;
}

await combinedRepo.pull({ source: fromRepo, force: true })
await combinedRepo.update({ clean: true, revision: 'default' })

let files = await Globby(['*', '!.hg'], { dot: true, cwd: combinedRepo.path })

await moveFiles(combinedRepo.path, Path.join(combinedRepo.path, name), files)
await combinedRepo.add()
try {
await combinedRepo.remove({ after: true })
} catch (errorInfo) {
if (!errorInfo.error.message.includes('still exists')) throw errorInfo.error;
}

await combinedRepo.commit(`Moving repository ${name} into folder ${name}`)

let name = Path.basename(fromRepo);
if (!mergedRepos.length) return;

if (mergedRepos.includes(name)) {
name += `-${ShortID.generate()}`;
await combinedRepo.merge()
try {
await combinedRepo.commit(`Merging ${name} into combined`)

} catch (errorInfo) {
if (!errorInfo.error.message.includes('nothing to merge') &&
!errorInfo.error.message.includes('merging with a working directory ancestor')) {
throw errorInfo.error;
}
}

mergedRepos.push(name);
}

return combinedRepo.pull({ source: fromRepo, force: true })
.then(() => combinedRepo.update({ clean: true, revision: 'default' }))
.then(() => Globby(['*', '!.hg'], { dot: true, cwd: combinedRepo.path }))
.then(files => moveFiles(combinedRepo.path, Path.join(combinedRepo.path, name), files))
.then(() => combinedRepo.add())
.then(() => combinedRepo.remove({ after: true }))
.catch((errorInfo) => {
if (!errorInfo.error.message.includes('still exists')) throw errorInfo.error;
})
.then(() => combinedRepo.commit(`Moving repository ${name} into folder ${name}`))
.then(() => {
if (!mergedRepos.length) return Promise.resolve();

return combinedRepo.merge()
.then(() => combinedRepo.commit(`Merging ${name} into combined`))
.catch((errorInfo) => {
if (!errorInfo.error.message.includes('nothing to merge') &&
!errorInfo.error.message.includes('merging with a working directory ancestor')) {
throw errorInfo.error;
}
});
})
.then(() => {
mergedRepos.push(name);
});
})
.then(() => combinedRepo);
return combinedRepo;
}

async function cloneSingleOrMultiple(from, to, pythonPath) {
Expand All @@ -70,9 +75,9 @@ async function cloneSingleOrMultiple(from, to, pythonPath) {
try {
await Command.run('hg clone', newRepo.path, [from, newRepo.path])
} catch (error) {
if (results.error.message.includes('not found')) {
throw new TypeError('Incorrect type of from parameter. Clone source not found');
}
if (results.error.message.includes('not found')) {
throw new TypeError('Incorrect type of from parameter. Clone source not found');
}
}

return newRepo;
Expand Down Expand Up @@ -126,7 +131,7 @@ class Hg {

gitify({ gitRepoPath = undefined } = {}, done = undefined) {
const repo = new HgRepo(undefined, this.pythonPath);
console.log(gitRepoPath)

return repo.gitify({ gitRepoPath })
.asCallback(done);
}
Expand Down

0 comments on commit 0e88d1a

Please sign in to comment.