Skip to content

Commit edcad3a

Browse files
authored
GitHub - use GitHub default branch name when publishing to GitHub (microsoft#183207)
1 parent 1e97f34 commit edcad3a

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

extensions/git/src/api/api1.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { Model } from '../model';
77
import { Repository as BaseRepository, Resource } from '../repository';
8-
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, ForcePushMode, Ref, Submodule, Commit, Change, RepositoryUIState, Status, LogOptions, APIState, CommitOptions, RefType, CredentialsProvider, BranchQuery, PushErrorHandler, PublishEvent, FetchOptions, RemoteSourceProvider, RemoteSourcePublisher, PostCommitCommandsProvider, RefQuery, BranchProtectionProvider } from './git';
8+
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, ForcePushMode, Ref, Submodule, Commit, Change, RepositoryUIState, Status, LogOptions, APIState, CommitOptions, RefType, CredentialsProvider, BranchQuery, PushErrorHandler, PublishEvent, FetchOptions, RemoteSourceProvider, RemoteSourcePublisher, PostCommitCommandsProvider, RefQuery, BranchProtectionProvider, InitOptions } from './git';
99
import { Event, SourceControlInputBox, Uri, SourceControl, Disposable, commands, CancellationToken } from 'vscode';
1010
import { combinedDisposable, mapEvent } from '../util';
1111
import { toGitUri } from '../uri';
@@ -294,9 +294,9 @@ export class ApiImpl implements API {
294294
return result ? new ApiRepository(result) : null;
295295
}
296296

297-
async init(root: Uri): Promise<Repository | null> {
297+
async init(root: Uri, options?: InitOptions): Promise<Repository | null> {
298298
const path = root.fsPath;
299-
await this._model.git.init(path);
299+
await this._model.git.init(path, options);
300300
await this._model.openRepository(path);
301301
return this.getRepository(root) || null;
302302
}

extensions/git/src/api/git.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ export interface FetchOptions {
156156
depth?: number;
157157
}
158158

159+
export interface InitOptions {
160+
defaultBranch?: string;
161+
}
162+
159163
export interface RefQuery {
160164
readonly contains?: string;
161165
readonly count?: number;
@@ -307,7 +311,7 @@ export interface API {
307311

308312
toGitUri(uri: Uri, ref: string): Uri;
309313
getRepository(uri: Uri): Repository | null;
310-
init(root: Uri): Promise<Repository | null>;
314+
init(root: Uri, options?: InitOptions): Promise<Repository | null>;
311315
openRepository(root: Uri): Promise<Repository | null>
312316

313317
registerRemoteSourcePublisher(publisher: RemoteSourcePublisher): Disposable;

extensions/git/src/git.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as filetype from 'file-type';
1515
import { assign, groupBy, IDisposable, toDisposable, dispose, mkdirp, readBytes, detectUnicodeEncoding, Encoding, onceEvent, splitInChunks, Limiter, Versions, isWindows, pathEquals } from './util';
1616
import { CancellationError, CancellationToken, ConfigurationChangeEvent, LogOutputChannel, Progress, Uri, workspace } from 'vscode';
1717
import { detectEncoding } from './encoding';
18-
import { Ref, RefType, Branch, Remote, ForcePushMode, GitErrorCodes, LogOptions, Change, Status, CommitOptions, RefQuery } from './api/git';
18+
import { Ref, RefType, Branch, Remote, ForcePushMode, GitErrorCodes, LogOptions, Change, Status, CommitOptions, RefQuery, InitOptions } from './api/git';
1919
import * as byline from 'byline';
2020
import { StringDecoder } from 'string_decoder';
2121

@@ -401,7 +401,7 @@ export class Git {
401401
return new Repository(this, repository, dotGit, logger);
402402
}
403403

404-
async init(repository: string, options: { defaultBranch?: string } = {}): Promise<void> {
404+
async init(repository: string, options: InitOptions = {}): Promise<void> {
405405
const args = ['init'];
406406

407407
if (options.defaultBranch && options.defaultBranch !== '') {

extensions/github/src/publish.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)
190190
progress.report({ message: vscode.l10n.t('Creating first commit'), increment: 25 });
191191

192192
if (!repository) {
193-
repository = await gitAPI.init(folder) || undefined;
193+
repository = await gitAPI.init(folder, { defaultBranch: createdGithubRepository.default_branch }) || undefined;
194194

195195
if (!repository) {
196196
return;

extensions/github/src/typings/git.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ export interface FetchOptions {
156156
depth?: number;
157157
}
158158

159+
export interface InitOptions {
160+
defaultBranch?: string;
161+
}
162+
159163
export interface BranchQuery {
160164
readonly remote?: boolean;
161165
readonly pattern?: string;
@@ -301,7 +305,7 @@ export interface API {
301305

302306
toGitUri(uri: Uri, ref: string): Uri;
303307
getRepository(uri: Uri): Repository | null;
304-
init(root: Uri): Promise<Repository | null>;
308+
init(root: Uri, options?: InitOptions): Promise<Repository | null>;
305309
openRepository(root: Uri): Promise<Repository | null>
306310

307311
registerRemoteSourcePublisher(publisher: RemoteSourcePublisher): Disposable;

0 commit comments

Comments
 (0)