diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2020-01-03 10:13:01 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-03 10:13:01 -0500 |
| commit | 9892bb4e3a7eb1577668c28c1e6f920ae9510a7f (patch) | |
| tree | 34fef078319d13c992d96e272967483fc9971ee6 /dist | |
| parent | 70ca8ea8edb415caab2746d59ac5ad8245858b1b (diff) | |
fix issue checking detached when git less than 2.22 (#128)
Diffstat (limited to 'dist')
| -rw-r--r-- | dist/index.js | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/dist/index.js b/dist/index.js index 2ef372e..1919193 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); } } @@ -4887,11 +4895,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-name', '--verify', '--quiet', 'HEAD'], true); + return !output.stdout.trim().startsWith('refs/heads/'); }); } lfsFetch(ref) { |
