Git - detect when HEAD is a tag (#170271)

* HEAD set when checking out a tag

* Remove more calls

* Remove tag references when in detached mode
This commit is contained in:
Ladislau Szomoru
2023-01-03 15:07:46 +01:00
committed by GitHub
parent 2c7fc7c978
commit 1d18dfc209
4 changed files with 28 additions and 33 deletions

View File

@@ -2077,17 +2077,22 @@ export class Repository {
}
}
async getHEADBranch(): Promise<Branch | undefined> {
async getHEADRef(): Promise<Branch | undefined> {
let HEAD: Branch | undefined;
try {
HEAD = await this.getHEAD();
if (HEAD.name) {
try {
HEAD = await this.getBranch(HEAD.name);
} catch (err) {
// noop
// Branch
HEAD = await this.getBranch(HEAD.name);
} else if (HEAD.commit) {
// Tag || Commit
const tags = await this.getRefs({ pattern: 'refs/tags/*' });
const tag = tags.find(tag => tag.commit === HEAD!.commit);
if (tag) {
HEAD = { ...HEAD, name: tag.name, type: RefType.Tag };
}
}
} catch (err) {