New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

git-checkout-interactive

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-checkout-interactive - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

57

index.js

@@ -1,6 +0,9 @@

const { spawn } = require('child_process')
#!/usr/bin/env node
const { promisify } = require('util')
const exec = promisify(require('child_process').exec)
const prompts = require('prompts')
async function run () {
const branches = await cmd('git branch -v --sort=-committerdate')
const { stdout: branches } = await exec('git branch -v --sort=-committerdate')

@@ -11,44 +14,36 @@ const choices = branches

.map(branch => {
const [, flag, name, info] = branch.match(/([* ])\s+([^\s]+)\s+(.+)/)
return {
value: name,
disabled: flag === '*',
info
}
const [, flag, value, hint] = branch.match(/([* ]) +([^ ]+) +(.+)/)
return { value, hint, disabled: flag === '*' }
})
const commits = choices.reduce((object, { value, info }) => ({
...object,
[value]: info
}), {})
const { branch } = await prompts({
type: 'select',
name: 'branch',
message: 'Select a branch',
message: 'Switch branch',
choices,
initial: 0,
hint: commits[choices[0].value],
warn: 'Current branch',
hint: choices[0].hint,
warn: 'current branch',
onState ({ value }) {
this.hint = commits[value]
this.hint = choices.find(c => c.value === value).hint
}
})
await cmd(`git checkout ${branch}`)
await checkout(branch)
}
function cmd (string) {
const [ cmd, ...args ] = string.split(' ')
return new Promise((resolve, reject) => {
const child = spawn(cmd, args)
let data = ''
child.stdout.on('data', buffer => {
data += buffer.toString()
})
child.stdout.on('end', () => resolve(data))
child.on('error', reject)
})
async function checkout (branch) {
if (!branch) return
const { stdout, stderr } = await exec(`git checkout ${branch}`)
process.stdout.write(stdout)
process.stderr.write(stderr)
}
run()
function onError (e) {
if (e.stderr) {
process.stderr.write(e.stderr)
} else {
console.error(e)
}
}
run().catch(onError)
{
"name": "git-checkout-interactive",
"version": "1.0.0",
"version": "1.0.1",
"description": "Quick switch between git branches",

@@ -5,0 +5,0 @@ "author": "Pete Cook",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc