Skip to content

Commit 2c5b430

Browse files
committed
Inherit group name, default branch, etc. when creating a new worktree
1 parent 6472cd6 commit 2c5b430

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

app/src/lib/stores/app-store.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7496,13 +7496,10 @@ export class AppStore extends TypedBaseStore<IAppState> {
74967496
? matchExistingRepository(repositories, addedRepo.mainWorktreePath)
74977497
: undefined
74987498

7499-
if (
7500-
mainWorktreeRepo !== undefined &&
7501-
isRepositoryWithGitHubRepository(mainWorktreeRepo)
7502-
) {
7503-
addedRepo = await this.repositoriesStore.setGitHubRepository(
7499+
if (mainWorktreeRepo !== undefined) {
7500+
addedRepo = await this.repositoriesStore.inheritConfiguration(
75047501
addedRepo,
7505-
mainWorktreeRepo.gitHubRepository
7502+
mainWorktreeRepo
75067503
)
75077504
}
75087505

app/src/lib/stores/repositories-store.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,43 @@ export class RepositoriesStore extends TypedBaseStore<
603603
)
604604
}
605605

606+
/**
607+
* Inherits the GitHub repository association, group name, default branch, workflow preferences, editor override, and login from the old repository
608+
*
609+
* @param newRepo The new repository to update with the old repository's configuration
610+
* @param oldRepo The repository to copy the configuration from
611+
* @returns
612+
*/
613+
public async inheritConfiguration(
614+
newRepo: Repository,
615+
oldRepo: Repository
616+
): Promise<Repository> {
617+
await this.db.transaction('rw', this.db.repositories, () =>
618+
this.db.repositories.update(newRepo.id, {
619+
gitHubRepositoryID: oldRepo.gitHubRepository?.dbID ?? null,
620+
groupName: oldRepo.groupName,
621+
defaultBranch: oldRepo.defaultBranch,
622+
workflowPreferences: oldRepo.workflowPreferences,
623+
customEditorOverride: oldRepo.customEditorOverride,
624+
})
625+
)
626+
this.emitUpdatedRepositories()
627+
628+
return new Repository(
629+
newRepo.path,
630+
newRepo.id,
631+
oldRepo.gitHubRepository,
632+
newRepo.missing,
633+
newRepo.alias,
634+
oldRepo.groupName,
635+
oldRepo.defaultBranch,
636+
oldRepo.workflowPreferences,
637+
oldRepo.customEditorOverride,
638+
newRepo.isTutorialRepository,
639+
oldRepo.overrideLogin
640+
)
641+
}
642+
606643
public async setGitHubRepository(repo: Repository, ghRepo: GitHubRepository) {
607644
// If nothing has changed we can skip writing to the database and (more
608645
// importantly) avoid telling store consumers that the repo store has

0 commit comments

Comments
 (0)