forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lifecycleScripts/submodules/index.js: async/await
See nodegit#1867.
- Loading branch information
Showing
1 changed file
with
60 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,61 @@ | ||
var path = require("path"); | ||
var rootDir = path.join(__dirname, "../.."); | ||
|
||
var gitExecutableLocation = require( | ||
path.join(rootDir, "./utils/gitExecutableLocation") | ||
); | ||
var submoduleStatus = require("./getStatus"); | ||
|
||
var exec = require(path.join(rootDir, "./utils/execPromise")); | ||
|
||
module.exports = function submodules() { | ||
return gitExecutableLocation() | ||
.catch(function() { | ||
console.error("[nodegit] ERROR - Compilation of NodeGit requires git " + | ||
"CLI to be installed and on the path"); | ||
|
||
throw new Error("git CLI is not installed or not on the path"); | ||
}) | ||
.then(function() { | ||
console.log("[nodegit] Checking submodule status"); | ||
return submoduleStatus(); | ||
}) | ||
.then(function(statuses) { | ||
function printSubmodule(submoduleName) { | ||
console.log("\t" + submoduleName); | ||
} | ||
|
||
var dirtySubmodules = statuses | ||
.filter(function(status) { | ||
return status.workDirDirty && !status.needsInitialization; | ||
}) | ||
.map(function(dirtySubmodule) { | ||
return dirtySubmodule.name; | ||
}); | ||
|
||
if (dirtySubmodules.length) { | ||
console.error( | ||
"[nodegit] ERROR - Some submodules have uncommited changes:" | ||
); | ||
dirtySubmodules.forEach(printSubmodule); | ||
console.error( | ||
"\nThey must either be committed or discarded before we build" | ||
); | ||
|
||
throw new Error("Dirty Submodules: " + dirtySubmodules.join(" ")); | ||
} | ||
|
||
var outOfSyncSubmodules = statuses | ||
.filter(function(status) { | ||
return status.onNewCommit && !status.needsInitialization; | ||
}) | ||
.map(function(outOfSyncSubmodule) { | ||
return outOfSyncSubmodule.name; | ||
}); | ||
|
||
if (outOfSyncSubmodules.length) { | ||
console.warn( | ||
"[nodegit] WARNING - Some submodules are pointing to an new commit:" | ||
); | ||
outOfSyncSubmodules.forEach(printSubmodule); | ||
console.warn("\nThey will not be updated."); | ||
} | ||
|
||
return statuses | ||
.filter(function(status) { | ||
return !status.onNewCommit; | ||
}) | ||
.reduce(function(chainPromise, submoduleToUpdate) { | ||
return chainPromise | ||
.then(function() { | ||
console.log( | ||
"[nodegit] Initializing submodule", | ||
submoduleToUpdate.name | ||
); | ||
return exec( | ||
"git submodule update --init --recursive " + | ||
submoduleToUpdate.name | ||
); | ||
}); | ||
}, Promise.resolve()); | ||
}); | ||
const path = require("path"); | ||
const rootDir = path.join(__dirname, "../.."); | ||
|
||
const gitExecutableLocation = require(path.join( | ||
rootDir, | ||
"./utils/gitExecutableLocation" | ||
)); | ||
const submoduleStatus = require("./getStatus"); | ||
|
||
const exec = require(path.join(rootDir, "./utils/execPromise")); | ||
|
||
module.exports = async function submodules() { | ||
try { | ||
await gitExecutableLocation(); | ||
} catch (_) { | ||
console.error( | ||
"[nodegit] ERROR - Compilation of NodeGit requires git " + | ||
"CLI to be installed and on the path" | ||
); | ||
|
||
throw new Error("git CLI is not installed or not on the path"); | ||
} | ||
|
||
console.log("[nodegit] Checking submodule status"); | ||
const statuses = await submoduleStatus(); | ||
|
||
function printSubmodule(submoduleName) { | ||
console.log("\t" + submoduleName); | ||
} | ||
|
||
const dirtySubmodules = statuses | ||
.filter((status) => status.workDirDirty && !status.needsInitialization) | ||
.map((dirtySubmodule) => dirtySubmodule.name); | ||
|
||
if (dirtySubmodules.length) { | ||
console.error("[nodegit] ERROR - Some submodules have uncommited changes:"); | ||
dirtySubmodules.forEach(printSubmodule); | ||
console.error( | ||
"\nThey must either be committed or discarded before we build" | ||
); | ||
|
||
throw new Error("Dirty Submodules: " + dirtySubmodules.join(" ")); | ||
} | ||
|
||
const outOfSyncSubmodules = statuses | ||
.filter((status) => status.onNewCommit && !status.needsInitialization) | ||
.map((outOfSyncSubmodule) => outOfSyncSubmodule.name); | ||
|
||
if (outOfSyncSubmodules.length) { | ||
console.warn( | ||
"[nodegit] WARNING - Some submodules are pointing to an new commit:" | ||
); | ||
outOfSyncSubmodules.forEach(printSubmodule); | ||
console.warn("\nThey will not be updated."); | ||
} | ||
|
||
for (const status of statuses.filter((s) => !s.onNewCommit)) { | ||
console.log("[nodegit] Initializing submodule", status.name); | ||
await exec("git submodule update --init --recursive " + status.name); | ||
} | ||
}; |