Last active
January 1, 2016 11:19
-
-
Save dbushong/8137418 to your computer and use it in GitHub Desktop.
Vanilla/Iced/Promise comparison for a git-exec'ing operation. Given an origin and a tag, return the SHA of the tag if it exists, else create a new tag and return that SHA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cp = require 'child_process' | |
git = (cmd, args, cb) -> # same as vanilla | |
cp.execFile 'git', [cmd].concat(args), (err, stdout) -> cb err, stdout.trim() | |
createTagIfMissing = (origin, tag, cb) -> | |
await git 'show-ref', [tag], defer err, showRef | |
if err? | |
await git 'tag', [tag], defer err | |
return cb err if err? | |
await | |
git 'show-ref', [tag], defer err1, showRef | |
git 'push', [origin, 'tag', tag], defer err2 | |
return cb err1 ? err2 if err1 ? err2 | |
cb null, showRef.split(' ')[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cp = require 'child_process' | |
Q = require 'q' | |
git = (cmd, args...) -> | |
Q.nfcall(cp.execFile, 'git', [cmd].concat args).get(0).invoke('trim') | |
createTagIfMissing = (origin, tag) -> | |
git('show-ref', tag) | |
.then((sr) -> sr.split(' ')[0]) | |
.catch -> | |
git('tag', tag) | |
.then(-> [ git('show-ref', tag), git('push', origin, 'tag', tag) ]) | |
.all().spread (sr) -> sr.split(' ')[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# NOTE: this isn't quite fair; this code should output the stderr on error | |
createTagIfMissing() { | |
local origin="$1" tag="$2" | |
if ! show_ref=`git show-ref $tag`; then | |
git tag $tag >/dev/null | |
git push $origin tag $tag >/dev/null 2>&1 & show_ref=`git show-ref $tag` | |
wait | |
fi | |
echo "$show_ref" | sed 's/ .*//' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cp = require 'child_process' | |
async = require 'async' | |
git = (cmd, args, cb) -> # same as iced | |
cp.execFile 'git', [cmd].concat(args), (err, stdout) -> cb err, stdout.trim() | |
createTagIfMissing = (origin, tag, cb) -> | |
git 'show-ref', [tag], (err, showRef) -> | |
if err? | |
git 'tag', [tag], (err) -> | |
return cb err if err? | |
async.parallel [ | |
(cb) -> git 'show-ref', [tag], cb | |
(cb) -> git 'push', [origin, 'tag', tag], cb | |
], (err, res) -> | |
return cb err if err? | |
cb null, res[0].split(' ')[0] | |
else | |
cb null, showRef.split(' ')[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment