Skip to content

Instantly share code, notes, and snippets.

@cstroliadavis
Last active June 8, 2020 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cstroliadavis/7a74aa32d2029d8d32e5d4a598cddf27 to your computer and use it in GitHub Desktop.
Save cstroliadavis/7a74aa32d2029d8d32e5d4a598cddf27 to your computer and use it in GitHub Desktop.
import {decodeUtf8} from './third_party.ts'
/**
* Gets the name of the git branch of the current working directory
* @returns {Promise<string>}
*
* @example
* // if on the main git branch
* console.log(await getGitBranch());
* // output: master
*/
export default async function getGitBranch(): Promise<string> {
const proc = Deno.run({ cmd: ['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout: 'piped'});
return (await decodeUtf8(await proc.output())).split('\n')[0];
}
if (import.meta.main) {
console.log(await getGitBranch());
}
export * as path from "https://deno.land/std/path/mod.ts";
export { decode as decodeUtf8 } from "https://deno.land/std/encoding/utf8.ts";
export { ensureDir } from "https://deno.land/std/fs/ensure_dir.ts";
export { exists as pathExists } from 'https://deno.land/std/fs/exists.ts'
export { serve } from "https://deno.land/std@0.55.0/http/server.ts";
export { sprintf } from 'https://deno.land/std/fmt/printf.ts';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment