Skip to content

Commit

Permalink
fix: 🐛 fix branch name is undefined when repo is detached
Browse files Browse the repository at this point in the history
  • Loading branch information
vivaxy committed Jun 15, 2020
1 parent 9caf53e commit e9c6945
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/lib/conventional-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ async function getRepository({
index,
label: folder?.name || path.basename(repo.rootUri.fsPath),
description:
`${repo.state.HEAD?.name}${hasChanges(repo) ? '*' : ''}` || '',
`${
repo.state.HEAD?.name || repo.state.HEAD?.commit?.slice(0, 8) || ''
}${hasChanges(repo) ? '*' : ''}` || '',
};
});

Expand Down
40 changes: 39 additions & 1 deletion src/vendors/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Uri, SourceControlInputBox, Event, CancellationToken } from 'vscode';
import { Uri, Event, Disposable, ProviderResult } from 'vscode';
export { ProviderResult } from 'vscode';

export interface Git {
readonly path: string;
Expand Down Expand Up @@ -119,6 +120,7 @@ export interface RepositoryUIState {
export interface LogOptions {
/** Max number of log entries to retrieve. If not specified, the default is 32. */
readonly maxEntries?: number;
readonly path?: string;
}

export interface CommitOptions {
Expand All @@ -129,6 +131,13 @@ export interface CommitOptions {
empty?: boolean;
}

export interface BranchQuery {
readonly remote?: boolean;
readonly pattern?: string;
readonly count?: number;
readonly contains?: string;
}

export interface Repository {
readonly rootUri: Uri;
readonly inputBox: InputBox;
Expand Down Expand Up @@ -172,6 +181,7 @@ export interface Repository {
createBranch(name: string, checkout: boolean, ref?: string): Promise<void>;
deleteBranch(name: string, force?: boolean): Promise<void>;
getBranch(name: string): Promise<Branch>;
getBranches(query: BranchQuery): Promise<Ref[]>;
setBranchUpstream(name: string, upstream: string): Promise<void>;

getMergeBase(ref1: string, ref2: string): Promise<string>;
Expand All @@ -181,6 +191,7 @@ export interface Repository {

addRemote(name: string, url: string): Promise<void>;
removeRemote(name: string): Promise<void>;
renameRemote(name: string, newName: string): Promise<void>;

fetch(remote?: string, ref?: string, depth?: number): Promise<void>;
pull(unshallow?: boolean): Promise<void>;
Expand All @@ -196,6 +207,29 @@ export interface Repository {
commit(message: string, opts?: CommitOptions): Promise<void>;
}

export interface RemoteSource {
readonly name: string;
readonly description?: string;
readonly url: string | string[];
}

export interface RemoteSourceProvider {
readonly name: string;
readonly icon?: string; // codicon name
readonly supportsQuery?: boolean;
getRemoteSources(query?: string): ProviderResult<RemoteSource[]>;
publishRepository?(repository: Repository): Promise<void>;
}

export interface Credentials {
readonly username: string;
readonly password: string;
}

export interface CredentialsProvider {
getCredentials(host: Uri): ProviderResult<Credentials>;
}

export type APIState = 'uninitialized' | 'initialized';

export interface API {
Expand All @@ -208,6 +242,10 @@ export interface API {

toGitUri(uri: Uri, ref: string): Uri;
getRepository(uri: Uri): Repository | null;
init(root: Uri): Promise<Repository | null>;

registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable;
registerCredentialsProvider(provider: CredentialsProvider): Disposable;
}

export interface GitExtension {
Expand Down

0 comments on commit e9c6945

Please sign in to comment.