From 44e1b123fcf5eed8c54fabbff3064e3ab22da7c3 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Thu, 2 Jan 2020 14:06:58 -0500 Subject: [PATCH 1/4] fix issue checking detached when git less than 2.22 --- dist/index.js | 8 +++----- src/git-command-manager.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2ef372eba..e04155f30 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4887,11 +4887,9 @@ class GitCommandManager { } isDetached() { return __awaiter(this, void 0, void 0, function* () { - // Note, this implementation uses "branch --show-current" because - // "rev-parse --symbolic-full-name HEAD" can fail on a new repo - // with nothing checked out. - const output = yield this.execGit(['branch', '--show-current']); - return output.stdout.trim() === ''; + // Note, "branch --show-current" would be simpler but isn't available until Git 2.22 + const output = yield this.execGit(['rev-parse', '--symbolic-full-nane', 'HEAD'], true); + return !output.stdout.trim().startsWith('refs/heads/'); }); } lfsFetch(ref) { diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index f86b8c0b3..bbf0878e8 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -170,12 +170,12 @@ class GitCommandManager { } async isDetached(): Promise { - // Note, this implementation uses "branch --show-current" because - // "rev-parse --symbolic-full-name HEAD" can fail on a new repo - // with nothing checked out. - - const output = await this.execGit(['branch', '--show-current']) - return output.stdout.trim() === '' + // Note, "branch --show-current" would be simpler but isn't available until Git 2.22 + const output = await this.execGit( + ['rev-parse', '--symbolic-full-nane', 'HEAD'], + true + ) + return !output.stdout.trim().startsWith('refs/heads/') } async lfsFetch(ref: string): Promise { From d7ab4a7a3d2138c0bee419eec8894dfbfe6b672d Mon Sep 17 00:00:00 2001 From: eric sciple Date: Thu, 2 Jan 2020 14:14:01 -0500 Subject: [PATCH 2/4] . --- dist/index.js | 2 +- src/git-command-manager.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index e04155f30..0e60e13b7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4888,7 +4888,7 @@ class GitCommandManager { isDetached() { return __awaiter(this, void 0, void 0, function* () { // Note, "branch --show-current" would be simpler but isn't available until Git 2.22 - const output = yield this.execGit(['rev-parse', '--symbolic-full-nane', 'HEAD'], true); + const output = yield this.execGit(['rev-parse', '--symbolic-full-name', 'HEAD'], true); return !output.stdout.trim().startsWith('refs/heads/'); }); } diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index bbf0878e8..0e75a8693 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -172,7 +172,7 @@ class GitCommandManager { async isDetached(): Promise { // Note, "branch --show-current" would be simpler but isn't available until Git 2.22 const output = await this.execGit( - ['rev-parse', '--symbolic-full-nane', 'HEAD'], + ['rev-parse', '--symbolic-full-name', 'HEAD'], true ) return !output.stdout.trim().startsWith('refs/heads/') From 1571d4fa5834ad50e44790a2a1101dd771663138 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Thu, 2 Jan 2020 17:04:36 -0500 Subject: [PATCH 3/4] . --- dist/index.js | 2 +- src/git-command-manager.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0e60e13b7..3b069ad75 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4888,7 +4888,7 @@ class GitCommandManager { isDetached() { return __awaiter(this, void 0, void 0, function* () { // Note, "branch --show-current" would be simpler but isn't available until Git 2.22 - const output = yield this.execGit(['rev-parse', '--symbolic-full-name', 'HEAD'], true); + const output = yield this.execGit(['rev-parse', '--symbolic-full-name', '--verify', '--quiet', 'HEAD'], true); return !output.stdout.trim().startsWith('refs/heads/'); }); } diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 0e75a8693..8085b80b1 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -172,7 +172,7 @@ class GitCommandManager { async isDetached(): Promise { // Note, "branch --show-current" would be simpler but isn't available until Git 2.22 const output = await this.execGit( - ['rev-parse', '--symbolic-full-name', 'HEAD'], + ['rev-parse', '--symbolic-full-name', '--verify', '--quiet', 'HEAD'], true ) return !output.stdout.trim().startsWith('refs/heads/') From e5d5317cf22bba7e67bc3e29673fa469b43ebae5 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Thu, 2 Jan 2020 17:42:52 -0500 Subject: [PATCH 4/4] . --- dist/index.js | 12 ++++++++++-- src/git-command-manager.ts | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3b069ad75..19191939c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4799,9 +4799,11 @@ class GitCommandManager { branchList(remote) { return __awaiter(this, void 0, void 0, function* () { const result = []; - // Note, this implementation uses "rev-parse --symbolic" because the output from + // Note, this implementation uses "rev-parse --symbolic-full-name" because the output from // "branch --list" is more difficult when in a detached HEAD state. - const args = ['rev-parse', '--symbolic']; + // Note, this implementation uses "rev-parse --symbolic-full-name" because there is a bug + // in Git 2.18 that causes "rev-parse --symbolic" to output symbolic full names. + const args = ['rev-parse', '--symbolic-full-name']; if (remote) { args.push('--remotes=origin'); } @@ -4812,6 +4814,12 @@ class GitCommandManager { for (let branch of output.stdout.trim().split('\n')) { branch = branch.trim(); if (branch) { + if (branch.startsWith('refs/heads/')) { + branch = branch.substr('refs/heads/'.length); + } + else if (branch.startsWith('refs/remotes/')) { + branch = branch.substr('refs/remotes/'.length); + } result.push(branch); } } diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 8085b80b1..74489c273 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -77,10 +77,12 @@ class GitCommandManager { async branchList(remote: boolean): Promise { const result: string[] = [] - // Note, this implementation uses "rev-parse --symbolic" because the output from + // Note, this implementation uses "rev-parse --symbolic-full-name" because the output from // "branch --list" is more difficult when in a detached HEAD state. + // Note, this implementation uses "rev-parse --symbolic-full-name" because there is a bug + // in Git 2.18 that causes "rev-parse --symbolic" to output symbolic full names. - const args = ['rev-parse', '--symbolic'] + const args = ['rev-parse', '--symbolic-full-name'] if (remote) { args.push('--remotes=origin') } else { @@ -92,6 +94,12 @@ class GitCommandManager { for (let branch of output.stdout.trim().split('\n')) { branch = branch.trim() if (branch) { + if (branch.startsWith('refs/heads/')) { + branch = branch.substr('refs/heads/'.length) + } else if (branch.startsWith('refs/remotes/')) { + branch = branch.substr('refs/remotes/'.length) + } + result.push(branch) } }