mirror of
https://github.com/desktop/desktop
synced 2024-09-19 08:02:22 +00:00
Move defaultBranch
from GH repos to all repos
This commit is contained in:
parent
83676b406e
commit
f0a6da59e3
|
@ -39,7 +39,7 @@ export function findDefaultUpstreamBranch(
|
|||
const foundBranch = branches.find(
|
||||
b =>
|
||||
b.type === BranchType.Remote &&
|
||||
b.name === `${UpstreamRemoteName}/${githubRepository.defaultBranch}`
|
||||
b.name === `${UpstreamRemoteName}/${repository.defaultBranch}`
|
||||
)
|
||||
|
||||
return foundBranch !== undefined ? foundBranch : null
|
||||
|
|
|
@ -22,7 +22,6 @@ export interface IDatabaseGitHubRepository {
|
|||
readonly name: string
|
||||
readonly private: boolean | null
|
||||
readonly htmlURL: string | null
|
||||
readonly defaultBranch: string | null
|
||||
readonly cloneURL: string | null
|
||||
|
||||
/** The database ID of the parent repository if the repository is a fork. */
|
||||
|
@ -51,6 +50,7 @@ export interface IDatabaseRepository {
|
|||
readonly id?: number
|
||||
readonly gitHubRepositoryID: number | null
|
||||
readonly path: string
|
||||
readonly defaultBranch: string | null
|
||||
readonly alias: string | null
|
||||
readonly missing: boolean
|
||||
|
||||
|
@ -138,6 +138,7 @@ export class RepositoriesDatabase extends BaseDatabase {
|
|||
|
||||
this.conditionalVersion(8, {}, ensureNoUndefinedParentID)
|
||||
this.conditionalVersion(9, { owners: '++id, &key' }, createOwnerKey)
|
||||
this.conditionalVersion(10, {}, migrateDefaultBranch)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,6 +235,22 @@ async function createOwnerKey(tx: Transaction) {
|
|||
await ownersTable.bulkDelete(ownersToDelete)
|
||||
}
|
||||
|
||||
async function migrateDefaultBranch(tx: Transaction) {
|
||||
const reposTable = tx.table<IDatabaseRepository, number>('repositories')
|
||||
const ghReposTable = tx.table<IDatabaseGitHubRepository, number>(
|
||||
'gitHubRepositories'
|
||||
)
|
||||
const allGHRepos = await ghReposTable.toArray()
|
||||
await reposTable.toCollection().modify(repo => {
|
||||
const ghRepo = allGHRepos.find(r => r.id === repo.gitHubRepositoryID)
|
||||
;(repo as any).defaultBranch = (ghRepo as any)?.defaultBranch ?? null
|
||||
})
|
||||
|
||||
await ghReposTable.toCollection().modify(repo => {
|
||||
delete (repo as any).defaultBranch
|
||||
})
|
||||
}
|
||||
|
||||
/* Creates a case-insensitive key used to uniquely identify an owner
|
||||
* based on the endpoint and login. Note that the key happens to
|
||||
* match the canonical API url for the user. This has no practical
|
||||
|
|
|
@ -508,13 +508,8 @@ export class GitStore extends BaseStore {
|
|||
* name conventions.
|
||||
*/
|
||||
private async resolveDefaultBranch(): Promise<string> {
|
||||
const { gitHubRepository } = this.repository
|
||||
if (
|
||||
!enableUpdateDefaultBranch() &&
|
||||
gitHubRepository &&
|
||||
gitHubRepository.defaultBranch != null
|
||||
) {
|
||||
return gitHubRepository.defaultBranch
|
||||
if (!enableUpdateDefaultBranch() && this.repository.defaultBranch != null) {
|
||||
return this.repository.defaultBranch
|
||||
}
|
||||
|
||||
if (this.currentRemote !== null) {
|
||||
|
|
|
@ -130,7 +130,6 @@ export class RepositoriesStore extends TypedBaseStore<
|
|||
repo.id,
|
||||
repo.private,
|
||||
repo.htmlURL,
|
||||
repo.defaultBranch,
|
||||
repo.cloneURL,
|
||||
repo.issuesEnabled,
|
||||
repo.isArchived,
|
||||
|
@ -152,6 +151,7 @@ export class RepositoriesStore extends TypedBaseStore<
|
|||
? await this.findGitHubRepositoryByID(repo.gitHubRepositoryID)
|
||||
: await Promise.resolve(null), // Dexie gets confused if we return null
|
||||
repo.missing,
|
||||
repo.defaultBranch,
|
||||
enableRepositoryAliases() ? repo.alias : null,
|
||||
repo.workflowPreferences,
|
||||
repo.isTutorialRepository
|
||||
|
@ -218,6 +218,7 @@ export class RepositoriesStore extends TypedBaseStore<
|
|||
alias: null,
|
||||
gitHubRepositoryID: ghRepo.dbID,
|
||||
missing: false,
|
||||
defaultBranch: apiRepo.default_branch,
|
||||
lastStashCheckDate: null,
|
||||
isTutorialRepository: true,
|
||||
})
|
||||
|
@ -252,6 +253,7 @@ export class RepositoriesStore extends TypedBaseStore<
|
|||
path,
|
||||
gitHubRepositoryID: null,
|
||||
missing: opts?.missing ?? false,
|
||||
defaultBranch: null,
|
||||
lastStashCheckDate: null,
|
||||
alias: null,
|
||||
}
|
||||
|
@ -287,6 +289,7 @@ export class RepositoriesStore extends TypedBaseStore<
|
|||
repository.id,
|
||||
repository.gitHubRepository,
|
||||
missing,
|
||||
repository.defaultBranch,
|
||||
repository.alias,
|
||||
repository.workflowPreferences,
|
||||
repository.isTutorialRepository
|
||||
|
@ -337,6 +340,7 @@ export class RepositoriesStore extends TypedBaseStore<
|
|||
repository.id,
|
||||
repository.gitHubRepository,
|
||||
false,
|
||||
repository.defaultBranch,
|
||||
repository.alias,
|
||||
repository.workflowPreferences,
|
||||
repository.isTutorialRepository
|
||||
|
@ -449,7 +453,6 @@ export class RepositoriesStore extends TypedBaseStore<
|
|||
|
||||
const skeletonRepo: IDatabaseGitHubRepository = {
|
||||
cloneURL: null,
|
||||
defaultBranch: null,
|
||||
htmlURL: null,
|
||||
lastPruneDate: null,
|
||||
name: match.name,
|
||||
|
@ -484,6 +487,7 @@ export class RepositoriesStore extends TypedBaseStore<
|
|||
repo.id,
|
||||
ghRepo,
|
||||
repo.missing,
|
||||
repo.defaultBranch,
|
||||
repo.alias,
|
||||
repo.workflowPreferences,
|
||||
repo.isTutorialRepository
|
||||
|
@ -557,7 +561,6 @@ export class RepositoriesStore extends TypedBaseStore<
|
|||
name: gitHubRepository.name,
|
||||
private: gitHubRepository.private,
|
||||
htmlURL: gitHubRepository.html_url,
|
||||
defaultBranch: gitHubRepository.default_branch,
|
||||
cloneURL: gitHubRepository.clone_url,
|
||||
parentID,
|
||||
lastPruneDate: existingRepo?.lastPruneDate ?? null,
|
||||
|
|
|
@ -22,7 +22,6 @@ export class GitHubRepository {
|
|||
public readonly dbID: number,
|
||||
public readonly isPrivate: boolean | null = null,
|
||||
public readonly htmlURL: string | null = null,
|
||||
public readonly defaultBranch: string | null = null,
|
||||
public readonly cloneURL: string | null = null,
|
||||
public readonly issuesEnabled: boolean | null = null,
|
||||
public readonly isArchived: boolean | null = null,
|
||||
|
@ -36,7 +35,6 @@ export class GitHubRepository {
|
|||
this.dbID,
|
||||
this.isPrivate,
|
||||
this.htmlURL,
|
||||
this.defaultBranch,
|
||||
this.cloneURL,
|
||||
this.issuesEnabled,
|
||||
this.isArchived,
|
||||
|
|
|
@ -51,6 +51,7 @@ export class Repository {
|
|||
public readonly id: number,
|
||||
public readonly gitHubRepository: GitHubRepository | null,
|
||||
public readonly missing: boolean,
|
||||
public readonly defaultBranch: string | null = null,
|
||||
public readonly alias: string | null = null,
|
||||
public readonly workflowPreferences: WorkflowPreferences = {},
|
||||
/**
|
||||
|
@ -68,6 +69,7 @@ export class Repository {
|
|||
this.id,
|
||||
gitHubRepository?.hash,
|
||||
this.missing,
|
||||
this.defaultBranch,
|
||||
this.alias,
|
||||
this.workflowPreferences.forkContributionTarget,
|
||||
this.isTutorialRepository
|
||||
|
|
|
@ -37,7 +37,6 @@ export function gitHubRepoFixture({
|
|||
owner,
|
||||
name,
|
||||
parent,
|
||||
defaultBranch,
|
||||
endpoint,
|
||||
isPrivate,
|
||||
}: IGitHubRepoFixtureOptions): GitHubRepository {
|
||||
|
@ -54,7 +53,6 @@ export function gitHubRepoFixture({
|
|||
id_counter++,
|
||||
isPrivate !== undefined ? isPrivate : null,
|
||||
htmlUrl,
|
||||
defaultBranch || 'master',
|
||||
`${htmlUrl}.git`,
|
||||
null,
|
||||
null,
|
||||
|
|
|
@ -17,7 +17,6 @@ describe('RepositoriesDatabase', () => {
|
|||
name: 'desktop',
|
||||
private: false,
|
||||
htmlURL: 'http://github.com/desktop/desktop',
|
||||
defaultBranch: 'master',
|
||||
cloneURL: 'http://github.com/desktop/desktop.git',
|
||||
parentID: null,
|
||||
lastPruneDate: null,
|
||||
|
@ -66,7 +65,6 @@ describe('RepositoriesDatabase', () => {
|
|||
name: 'desktop',
|
||||
private: false,
|
||||
htmlURL: 'http://github.com/desktop/desktop',
|
||||
defaultBranch: 'master',
|
||||
cloneURL: 'http://github.com/desktop/desktop.git',
|
||||
parentID: null,
|
||||
lastPruneDate: null,
|
||||
|
@ -78,7 +76,6 @@ describe('RepositoriesDatabase', () => {
|
|||
name: 'dugite',
|
||||
private: false,
|
||||
htmlURL: 'http://github.com/desktop/dugite',
|
||||
defaultBranch: 'master',
|
||||
cloneURL: 'http://github.com/desktop/dugite.git',
|
||||
parentID: null,
|
||||
lastPruneDate: null,
|
||||
|
|
|
@ -163,7 +163,6 @@ describe('repository-matching', () => {
|
|||
},
|
||||
isPrivate: false,
|
||||
htmlURL: 'https://github.com/shiftkey/desktop',
|
||||
defaultBranch: 'master',
|
||||
parent: null,
|
||||
endpoint: 'https://api.github.com/',
|
||||
fork: true,
|
||||
|
|
Loading…
Reference in a new issue