import url from 'url';
import child from 'child_process';

function exec(cmd, options) {
  return new Promise((resolve, reject) => {
    child.exec(cmd, { cwd: options.path }, (err, stdout, stderr) => {
      if (err) {
        reject(err);
      } else {
        resolve(stdout.trim());
      }
    });
  });
}

function getCurrentBranch(options) {
  return exec(`git symbolic-ref HEAD | sed 's!refs\/heads\/!!'`, options); // TODO Remove `sed` for Windows support
}

function getLatestCommitHash(options) {
  return exec(`git log -n 1 --pretty=format:"%H"`, options);
}

function getOriginRemoteUrl(options) {
  return exec(`git config --get remote.origin.url`, options).then(getSafeRepositoryUrl);
}

function getSafeRepositoryUrl(repositoryUrl) {
  const parsed = url.parse(repositoryUrl);
  parsed.auth = null;
  return url.format(parsed);
}

export {
  getCurrentBranch,
  getLatestCommitHash,
  getOriginRemoteUrl,
  getSafeRepositoryUrl,
};

@@ -52,16 +52,79 @@
 cess';%0A%0A
+const debug = require('debug')('webpack-bugsnag-plugin:git');%0A%0A
 function
@@ -288,20 +288,174 @@
     
-reject(err);
+if (options.volatile) %7B%0A          reject(err);%0A        %7D else %7B%0A          debug(%60exec %22$%7Bcmd%7D%22 resulted in error: $%7Berr.message%7D%60);%0A          resolve(null);%0A        %7D
 %0A   
@@ -874,24 +874,61 @@
 n.url%60, 
-options)
+%7B%0A    ...options,%0A    volatile: true,%0A  %7D)%0A  
 .then(ge
@@ -946,16 +946,37 @@
 toryUrl)
+%0A  .catch(() =%3E null)
 ;%0A%7D%0A%0Afun

Make the git helper functions resolve `null` on error