From d762eb798d3fc10e7ae1915ebc36408e01d30ec1 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 9 Feb 2018 00:06:06 -0500 Subject: [PATCH] Fixes #276 - branches w/o upstream failed --- CHANGELOG.md | 3 +++ src/git/git.ts | 37 +++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c41e24..755786a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Added - Adds `gitlens.statusBar.reduceFlicker` setting to specify whether to reduce the status bar "flickering" when changing lines by not first clearing the previous blame information -- closes [#272](https://github.com/eamodio/vscode-gitlens/issues/272) +### Fixed +- Fixes [#276](https://github.com/eamodio/vscode-gitlens/issues/276) - Lookup for branches without upstreams fails + ## [8.0.0] - 2018-02-07 ### Added - Adds an all-new GitLens welcome page via the *Welcome* (`gitlens.showWelcomePage`) command — provides a welcome / onboarding experience — closes [#51](https://github.com/eamodio/vscode-gitlens/issues/51) diff --git a/src/git/git.ts b/src/git/git.ts index b7d8c0d..ceef398 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -1,5 +1,5 @@ 'use strict'; -import { Strings } from '../system'; +import { Objects, Strings } from '../system'; import { findGitPath, IGit } from './gitLocator'; import { Logger } from '../logger'; import { CommandOptions, runCommand } from './shell'; @@ -56,16 +56,17 @@ const stashFormat = [ const defaultStashParams = ['stash', 'list', '--name-status', '-M', `--format=${stashFormat}`]; -const GitWarnings = [ - /Not a git repository/, - /is outside repository/, - /no such path/, - /does not have any commits/, - /Path \'.*?\' does not exist in/, - /Path \'.*?\' exists on disk, but not in/, - /no upstream configured for branch/, - /ambiguous argument '.*?': unknown revision or path not in the working tree/ -]; +const GitWarnings = { + notARepository: /Not a git repository/, + outsideRepository: /is outside repository/, + noPath: /no such path/, + noCommits: /does not have any commits/, + notFound: /Path \'.*?\' does not exist in/, + foundButNotInRevision: /Path \'.*?\' exists on disk, but not in/, + headNotABranch: /HEAD does not point to a branch/, + noUpstream: /no upstream configured for branch \'(.*?)\'/, + unknownRevision: /ambiguous argument \'.*?\': unknown revision or path not in the working tree/ +}; async function gitCommand(options: CommandOptions & { readonly correlationKey?: string }, ...args: any[]): Promise { try { @@ -133,7 +134,7 @@ async function gitCommandCore(options: CommandOptions & { readonly correlationKe function gitCommandDefaultErrorHandler(ex: Error, options: CommandOptions, ...args: any[]): string { const msg = ex && ex.toString(); if (msg) { - for (const warning of GitWarnings) { + for (const warning of Objects.values(GitWarnings)) { if (warning.test(msg)) { Logger.warn('git', ...args, ` cwd='${options.cwd}'`, `\n ${msg.replace(/\r?\n|\r/g, ' ')}`); return ''; @@ -526,10 +527,12 @@ export class Git { } catch (ex) { const msg = ex && ex.toString(); - if (/HEAD does not point to a branch/.test(msg)) return undefined; - if (/no upstream configured for branch/.test(msg)) return ex.message.split('\n')[0]; + if (GitWarnings.headNotABranch.test(msg)) return undefined; - if (/ambiguous argument '.*?': unknown revision or path not in the working tree/.test(msg)) { + const result = GitWarnings.noUpstream.exec(msg); + if (result !== null) return result[1]; + + if (GitWarnings.unknownRevision.test(msg)) { try { const params = ['symbolic-ref', '-q', '--short', 'HEAD']; const data = await gitCommandCore(opts, ...params); @@ -573,9 +576,7 @@ export class Git { } catch (ex) { const msg = ex && ex.toString(); - if (/Path \'.*?\' does not exist in/.test(msg) || /Path \'.*?\' exists on disk, but not in /.test(msg)) { - return undefined; - } + if (GitWarnings.notFound.test(msg) || GitWarnings.foundButNotInRevision.test(msg)) return undefined; return gitCommandDefaultErrorHandler(ex, opts, args); }