dugite icon indicating copy to clipboard operation
dugite copied to clipboard

A more opinionated entry point

Open shiftkey opened this issue 8 years ago • 0 comments

The infamous @paulcbetts tweeted this at me:

You should steal https://github.com/surf-build/surf/pull/75/files#diff-c7ba9741682b21471b9c2842c396f106R18 for Dugite, it's a bit more Ergonomic of a function

Here's the snippet:

let askPassPath: string;
export async function git(args: string[], cwd: string, token?: string): Promise<string> {
  let ourToken = token || process.env.GITHUB_TOKEN;
  if (!askPassPath) {
    askPassPath = findActualExecutable('git-askpass-env', []).cmd;
  }

  d(`Actually using token! ${ourToken}`);
  process.env.GIT_ASKPASS = askPassPath;
  process.env.GIT_ASKPASS_USER = ourToken;
  process.env.GIT_ASKPASS_PASSWORD = 'x-oauth-basic';

  d(`Running command: git ${args.join(' ')} in ${cwd}`);
  let ret = await GitProcess.exec(args, cwd);
  if (ret.exitCode !== 0) {
    throw new Error(`Failed with exit code ${ret.exitCode}\n${ret.stderr}`);
  }

  return ret.stdout.trim();
}

Why? He followed up:

But like, trim is an easy win, and failed exit codes should definitely == failed Promise

This would be neat to help with the "Hello world!" sorts of examples that people might want to use this library for.

There's a few things around the internals and API surface that I'd like to get to around Other Priorities™ but if someone wants to have a go at this I'm happy to review and guide the actual implementation and where this fits.

shiftkey avatar Feb 21 '18 03:02 shiftkey