last-commit-log
Advanced tools
Comparing version 1.0.7 to 1.0.8
38
index.js
'use strict' | ||
const gitRemoteOriginUrl = require('git-remote-origin-url') | ||
const promisify = require('util').promisify | ||
const exec = promisify(require('child_process').exec) | ||
@@ -11,4 +13,2 @@ module.exports = class LCL { | ||
async getLastCommit () { | ||
const promisify = require('util').promisify | ||
const exec = promisify(require('child_process').exec) | ||
const prettyFormat = [ | ||
@@ -30,8 +30,4 @@ '%h', '%H', '%s', '%f', '%b', | ||
c = stdout.split(splitCharacter) | ||
const { stdout: revParseBranch } = await exec('git rev-parse --abbrev-ref HEAD', opts) | ||
const { stdout: nameRevBranch } = await exec('git name-rev --name-only HEAD', opts) | ||
gitBranch = await getGitBranch(opts) | ||
const { stdout: tag } = await exec('git tag --contains HEAD', opts) | ||
const branch1 = revParseBranch.trim() | ||
const branch2 = nameRevBranch.trim().replace('remotes/origin/', '') | ||
gitBranch = branch1 === 'HEAD' ? branch2 : branch1 | ||
gitTag = tag.trim() | ||
@@ -84,1 +80,29 @@ gitRemote = await gitRemoteOriginUrl(this.cwd) | ||
} | ||
async function getGitBranch (opts = {}) { | ||
let _branch = '' | ||
const [ | ||
{ stdout: revParseBranch }, | ||
{ stdout: nameRevBranch }, | ||
{ stdout: gitLogBranch } | ||
] = await Promise.all([ | ||
exec('git rev-parse --abbrev-ref HEAD', opts), | ||
exec('git name-rev --name-only HEAD', opts), | ||
exec('git log -n 1 --pretty=%d HEAD', opts) | ||
]) | ||
const branch1 = revParseBranch.trim() | ||
const branch2 = nameRevBranch.trim().replace('remotes/origin/', '') | ||
const branch3 = gitLogBranch.split(',') | ||
.filter(i => i.includes('origin/')) | ||
.map(i => i.trim()) | ||
.map(i => i.split('/')[1]) | ||
.map(i => i.replace(/[()]/, '')) | ||
.filter(i => i !== 'HEAD') | ||
_branch = branch1 !== 'HEAD' | ||
? branch1 | ||
: !branch2.startsWith('tags/') | ||
? branch2 : branch3.length > 1 | ||
? branch3.filter(i => i !== 'master')[0] : branch3[0] | ||
return _branch | ||
} |
{ | ||
"name": "last-commit-log", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "read git last commit log", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
7799
98