You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

git-branch-description

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-branch-description - npm Package Compare versions

Comparing version
1.1.8
to
1.1.9
+27
command/find.js
const os = require('os');
const parser = require('../util/parser');
const git = require('../util/git');
const output = require('../util/out');
module.exports = function(re) {
const descConfig = parser.read();
const branches = git.allBranches(true);
let out = [], br, regex = new RegExp(re);
for(let name of branches) {
br = {};
br.name = name;
br.desc = descConfig[name] || git.branchDescription(name);
if (br.desc.match(regex) || br.name.match(regex)) {
br.desc = br.desc.replace(regex, function(str) {
return `\x1B[31m${str}\x1B[39m`;
});
br.name = br.name.replace(regex, function(str) {
return `\x1B[31m${str}\x1B[39m`;
});
out.push(br);
}
}
output.outputDescription(out);
}
var os = require('os');
var git = require('./git');
function renderPrefix(isCurrent) {
return isCurrent ? '*' : ' ';
}
function colorName(name, isCurrent) {
if (isCurrent) {
return `\x1B[32m${name.replace('\x1B[39m', '\x1B[39m\x1B[32m')}\x1B[39m`;
} else {
return name;
}
}
function colorDesc(desc) {
if (desc) {
return ` \x1B[36m${desc.replace('\x1B[39m', '\x1B[39m\x1B[36m')}\x1B[39m`;
} else {
return '';
}
}
function isCurrentBranch(name) {
const currentBranch = git.currentHead();
name = name.replace(/\x1B\[\d+m/g, '');
return name === currentBranch;
}
exports.outputDescription = function (descs) {
let out = descs.map(({name, desc}) => {
var isCurrent = isCurrentBranch(name);
return `${renderPrefix(isCurrent)} ${colorName(name, isCurrent)} ${colorDesc(desc)}`;
});
console.log(out.join(os.EOL).toString());
}
+11
-2

@@ -16,2 +16,3 @@ #!/usr/bin/env node

var edit = require('../command/edit');
var find = require('../command/find');

@@ -24,3 +25,4 @@ var check = require('../util/check');

check.gitDir();
check.invariantGitDir(check.isGitDir());
program.command('init')

@@ -85,4 +87,11 @@ .description('initialize a git repository with a branch-description.properties')

})
})
});
program.command('find <regex>')
.description('find branch which name or descrition matches regex')
.action(function(regex) {
find(regex);
});
program.parse(process.argv);
+2
-2
var check = require('../util/check');
if (check.gitDir(true)) {
if (check.isGitDir()) {
try {
require('./init')();
require('./init')();
} catch (e) {

@@ -7,0 +7,0 @@

@@ -1,40 +0,6 @@

var os = require('os');
var parser = require('../util/parser');
var git = require('../util/git');
var output = require('../util/out');
var currentBranch = git.currentHead();
function renderPrefix(isCurrent) {
return isCurrent ? '*' : ' ';
}
function colorName(name, isCurrent) {
if (isCurrent) {
return `\x1B[32m${name}\x1B[39m`;
} else {
return name;
}
}
function colorDesc(desc) {
if (desc) {
return ` \x1B[36m${desc}\x1B[39m`;
} else {
return '';
}
}
function isCurrentBranch(name) {
return name === currentBranch;
}
function outputDescription(descs) {
let out = descs.map(({name, desc}) => {
var isCurrent = isCurrentBranch(name);
return `${renderPrefix(isCurrent)} ${colorName(name, isCurrent)} ${colorDesc(desc)}`;
});
console.log(out.join(os.EOL).toString());
}
module.exports = function(specifyBranch, mode, clean) {

@@ -50,3 +16,3 @@

};
return outputDescription([sbr]);
return output.outputDescription([sbr]);
}

@@ -73,3 +39,3 @@

outputDescription(out);
output.outputDescription(out);
}
{
"name": "git-branch-description",
"version": "1.1.8",
"version": "1.1.9",
"description": "manage branch description via branch-description.properties",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,12 +5,21 @@ var fs = require('fs');

var pwd = parser.getRootDir();
var pwd = parser.getRootDir();
exports.gitDir = function(rv) {
var isGitDir = fs.existsSync(path.resolve(pwd, '.git'));
if (!rv && !isGitDir) {
console.error('\x1B[31mNot a git repository.\x1B[39m');
exports.isGitDir = function() {
return fs.existsSync(path.resolve(pwd, '.git'));
}
exports.invariant = function(val, message) {
if (!val) {
console.log(`\x1B[31m${message}\x1B[39m`);
process.exit(1);
} else {
return isGitDir;
}
}
exports.invariantGitDir = function(val) {
if (!val) {
this.invariant(false, 'Not a git repository');
}
}