1
0
Fork 0
mirror of https://github.com/actions/checkout synced 2024-12-22 13:12:42 +00:00

fix issue checking detached when git less than 2.22 (#128)

This commit is contained in:
eric sciple 2020-01-03 10:13:01 -05:00 committed by GitHub
parent f466b96953
commit ae525b2262
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 15 deletions

20
dist/index.js vendored
View file

@ -4799,9 +4799,11 @@ class GitCommandManager {
branchList(remote) { branchList(remote) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const result = []; 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. // "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) { if (remote) {
args.push('--remotes=origin'); args.push('--remotes=origin');
} }
@ -4812,6 +4814,12 @@ class GitCommandManager {
for (let branch of output.stdout.trim().split('\n')) { for (let branch of output.stdout.trim().split('\n')) {
branch = branch.trim(); branch = branch.trim();
if (branch) { 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); result.push(branch);
} }
} }
@ -4887,11 +4895,9 @@ class GitCommandManager {
} }
isDetached() { isDetached() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// Note, this implementation uses "branch --show-current" because // Note, "branch --show-current" would be simpler but isn't available until Git 2.22
// "rev-parse --symbolic-full-name HEAD" can fail on a new repo const output = yield this.execGit(['rev-parse', '--symbolic-full-name', '--verify', '--quiet', 'HEAD'], true);
// with nothing checked out. return !output.stdout.trim().startsWith('refs/heads/');
const output = yield this.execGit(['branch', '--show-current']);
return output.stdout.trim() === '';
}); });
} }
lfsFetch(ref) { lfsFetch(ref) {

View file

@ -77,10 +77,12 @@ class GitCommandManager {
async branchList(remote: boolean): Promise<string[]> { async branchList(remote: boolean): Promise<string[]> {
const result: string[] = [] 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. // "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) { if (remote) {
args.push('--remotes=origin') args.push('--remotes=origin')
} else { } else {
@ -92,6 +94,12 @@ class GitCommandManager {
for (let branch of output.stdout.trim().split('\n')) { for (let branch of output.stdout.trim().split('\n')) {
branch = branch.trim() branch = branch.trim()
if (branch) { 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) result.push(branch)
} }
} }
@ -170,12 +178,12 @@ class GitCommandManager {
} }
async isDetached(): Promise<boolean> { async isDetached(): Promise<boolean> {
// Note, this implementation uses "branch --show-current" because // Note, "branch --show-current" would be simpler but isn't available until Git 2.22
// "rev-parse --symbolic-full-name HEAD" can fail on a new repo const output = await this.execGit(
// with nothing checked out. ['rev-parse', '--symbolic-full-name', '--verify', '--quiet', 'HEAD'],
true
const output = await this.execGit(['branch', '--show-current']) )
return output.stdout.trim() === '' return !output.stdout.trim().startsWith('refs/heads/')
} }
async lfsFetch(ref: string): Promise<void> { async lfsFetch(ref: string): Promise<void> {