@lerna/git-utils
Advanced tools
Comparing version 3.0.0-beta.0 to 3.0.0-beta.3
51
index.js
@@ -137,11 +137,13 @@ "use strict"; | ||
function diffSinceIn(committish, location, opts) { | ||
const args = ["diff", "--name-only", committish]; | ||
const formattedLocation = slash(path.relative(opts.cwd, location)); | ||
if (formattedLocation) { | ||
// avoid same-directory path.relative() === "" | ||
args.push("--", formattedLocation); | ||
} | ||
log.silly("diffSinceIn", committish, formattedLocation); | ||
const diff = ChildProcessUtilities.execSync( | ||
"git", | ||
["diff", "--name-only", committish, "--", formattedLocation], | ||
opts | ||
); | ||
const diff = ChildProcessUtilities.execSync("git", args, opts); | ||
log.silly("diff", diff); | ||
@@ -213,2 +215,38 @@ | ||
function fetchGitRemote(opts) { | ||
log.silly("fetchGitRemote"); | ||
ChildProcessUtilities.execSync("git", ["remote", "update"], opts); | ||
} | ||
function isBehindUpstream(gitRemote, opts) { | ||
log.silly("isBehindUpstream"); | ||
exports.fetchGitRemote(opts); | ||
const status = exports.aheadBehindCount(gitRemote, opts); | ||
const behind = status.behind >= 1; | ||
log.verbose("isBehindUpstream", behind); | ||
return behind; | ||
} | ||
function aheadBehindCount(gitRemote, opts) { | ||
const branchName = exports.getCurrentBranch(opts); | ||
const branchComparator = `${gitRemote}/${branchName}...${branchName}`; | ||
const rawAheadBehind = ChildProcessUtilities.execSync( | ||
"git", | ||
["rev-list", "--left-right", "--count", branchComparator], | ||
opts | ||
); | ||
const aheadBehind = rawAheadBehind.split("\t"); | ||
const behind = parseInt(aheadBehind[0], 10); | ||
const ahead = parseInt(aheadBehind[1], 10); | ||
log.silly( | ||
"aheadBehindCount", | ||
`behind ${gitRemote}/${branchName} by ${behind} commits; ${branchName} is ahead by ${ahead} commits` | ||
); | ||
return { ahead, behind }; | ||
} | ||
exports.isDetachedHead = isDetachedHead; | ||
@@ -234,1 +272,4 @@ exports.isInitialized = isInitialized; | ||
exports.hasCommit = hasCommit; | ||
exports.fetchGitRemote = fetchGitRemote; | ||
exports.isBehindUpstream = isBehindUpstream; | ||
exports.aheadBehindCount = aheadBehindCount; |
{ | ||
"name": "@lerna/git-utils", | ||
"version": "3.0.0-beta.0", | ||
"version": "3.0.0-beta.3", | ||
"description": "TODO", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "349b9c765bcbf38988d1fcd48313422417a04c8f" | ||
"gitHead": "1ee15326adf778c32e4b136bbfb27e1c899716a1" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8910
4
209