Comparing version 0.2.0 to 0.2.1
35
index.js
@@ -8,3 +8,4 @@ var exec = require('child_process').exec; | ||
var hash = info.hash; | ||
var originalBranch = info.branch; | ||
var detachedHead = info.detachedHead; | ||
var originalBranch = detachedHead ? hash : info.branch; | ||
@@ -38,3 +39,3 @@ var directory = opts.dir; | ||
.then(pushDirToRemote.bind(null, remote, remoteBranch)) | ||
.then(resetBranch.bind(null, originalBranch)) | ||
.then(resetBranch.bind(null, originalBranch, detachedHead)) | ||
.then(cleanup ? deleteLocalBranch.bind(null, local) : null) | ||
@@ -69,5 +70,6 @@ .catch(handleError); | ||
function resetBranch(branch) { | ||
function resetBranch(branch, detach) { | ||
var detached = detach ? '--detach ' : ''; | ||
return execCmd( | ||
'git checkout -f ' + branch, | ||
'git checkout -f ' + detached + branch, | ||
'problem resetting branch' | ||
@@ -123,8 +125,11 @@ ); | ||
getLastCommitHash(), | ||
getCurrentBranch() | ||
getCurrentBranch(), | ||
checkIfDetachedHead() | ||
]) | ||
.then(function(info) { | ||
info = info.map(function(s) { return s.trim(); }); | ||
return { | ||
hash: info[0].trim(), | ||
branch: info[1].trim() | ||
hash: info[0], | ||
branch: info[1], | ||
detachedHead: info[2] === 'true' | ||
}; | ||
@@ -141,3 +146,15 @@ }); | ||
function checkIfDetachedHead() { | ||
return execCmd( | ||
'CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`;' + | ||
'git symbolic-ref --short -q HEAD;' + | ||
'if [ $? -eq 1 ] && [ "$CURRENT_BRANCH" = "HEAD" ];' + | ||
'then echo "true";' + | ||
'else echo "false";' + | ||
'fi', | ||
'problem checking if detached head' | ||
); | ||
} | ||
/** | ||
@@ -154,3 +171,3 @@ * Helpers | ||
return new Promise(function(resolve, reject) { | ||
exec(cmd, function (error, stdout, stderr) { | ||
exec(cmd, function(error, stdout, stderr) { | ||
error ? reject(errMessage) : resolve(stdout); | ||
@@ -163,3 +180,3 @@ }); | ||
return new Promise(function(resolve, reject) { | ||
exec(cmd, function (error, stdout, stderr) { | ||
exec(cmd, function(error, stdout, stderr) { | ||
(error || stdout.length || stderr.length) ? reject(errMessage) : resolve(); | ||
@@ -166,0 +183,0 @@ }); |
{ | ||
"name": "push-dir", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Push a directory to a remote branch", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -53,3 +53,9 @@ var test = require('tape'); | ||
test('test works - cleanup detached head', function (t) { | ||
var cmds = fixtureTestCommands('test-works-cleanup-detached-head.sh'); | ||
exec(cmds, shouldWork.bind(null, t)); | ||
t.plan(1); | ||
}); | ||
function fixtureTestCommands(fixture) { | ||
@@ -69,4 +75,3 @@ return commands( | ||
'cp -r ../fixture-working ../fixture-remote', | ||
'PUSH_DIR=$PD_ROOT/bin/push-dir.js ./' + fixture, | ||
'cd $PD_ROOT/test' | ||
'PUSH_DIR=$PD_ROOT/bin/push-dir.js ./' + fixture | ||
); | ||
@@ -73,0 +78,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
49208
28
248
2