Skip to content

Commit c6c1c08

Browse files
committed
Fix preferred worktree restoration
This broke when we added worktrees in the sidebar
1 parent 06c1e6d commit c6c1c08

4 files changed

Lines changed: 9 additions & 11 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,8 +2175,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
21752175
/** This shouldn't be called directly. See `Dispatcher`. */
21762176
public async _selectRepository(
21772177
repository: Repository | CloningRepository | null,
2178-
persistSelection: boolean = true,
2179-
followPreferredWorktree: boolean = true
2178+
persistSelection: boolean = true
21802179
): Promise<Repository | null> {
21812180
const previouslySelectedRepository = this.selectedRepository
21822181

@@ -2212,7 +2211,8 @@ export class AppStore extends TypedBaseStore<IAppState> {
22122211
// When returning to a repository that has worktrees, restore the
22132212
// previously active linked worktree so the user doesn't always land
22142213
// on the main worktree after switching repos.
2215-
if (followPreferredWorktree && !repository.isLinkedWorktree) {
2214+
// Disable this behavior if "Show worktrees in repository list" is enabled.
2215+
if (!this.showWorktreesInSidebar && !repository.isLinkedWorktree) {
22162216
const repoPath = normalizePath(repository.path)
22172217
const preferredPath = getPreferredWorktreePath(repoPath)
22182218

app/src/ui/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3867,7 +3867,7 @@ export class App extends React.Component<IAppProps, IAppState> {
38673867
}
38683868

38693869
private onSelectionChanged = (repository: Repository | CloningRepository) => {
3870-
this.props.dispatcher.selectRepository(repository, true, false)
3870+
this.props.dispatcher.selectRepository(repository, true)
38713871
this.props.dispatcher.closeFoldout(FoldoutType.Repository)
38723872
}
38733873

app/src/ui/dispatcher/dispatcher.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,9 @@ export class Dispatcher {
314314
/** Select the repository. */
315315
public selectRepository(
316316
repository: Repository | CloningRepository,
317-
persistSelection: boolean = true,
318-
followPreferredWorktree: boolean = true
317+
persistSelection: boolean = true
319318
): Promise<Repository | null> {
320-
return this.appStore._selectRepository(
321-
repository,
322-
persistSelection,
323-
followPreferredWorktree
324-
)
319+
return this.appStore._selectRepository(repository, persistSelection)
325320
}
326321

327322
/** Change the selected section in the repository. */

app/src/ui/worktrees/rename-worktree-dialog.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Dialog, DialogContent, DialogFooter } from '../dialog'
77
import { TextBox } from '../lib/text-box'
88
import { OkCancelButtonGroup } from '../dialog/ok-cancel-button-group'
99
import { moveWorktree } from '../../lib/git/worktree'
10+
import { setPreferredWorktreePath } from '../../lib/worktree-preferences'
1011

1112
interface IRenameWorktreeDialogProps {
1213
readonly repository: Repository
@@ -45,12 +46,14 @@ export class RenameWorktreeDialog extends React.Component<
4546
this.setState({ renaming: true })
4647

4748
const storedRepo = await dispatcher.getRepositoryForPath(worktreePath)
49+
const mainRepoPath = storedRepo?.mainWorktreePath ?? repository.path
4850

4951
try {
5052
await moveWorktree(repository, worktreePath, newPath)
5153
if (storedRepo !== null) {
5254
await dispatcher.updateRepositoryPath(storedRepo, newPath)
5355
}
56+
setPreferredWorktreePath(mainRepoPath, newPath)
5457
} catch (e) {
5558
dispatcher.postError(e)
5659
return

0 commit comments

Comments
 (0)