Skip to content

Commit

Permalink
Merge pull request desktop#19694 from desktop/defer-validation
Browse files Browse the repository at this point in the history
Don't execute rev-parse unless we have to
  • Loading branch information
niik authored Dec 11, 2024
2 parents 1a8a45f + 8564890 commit b115199
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions app/src/ui/dispatcher/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
getCommitsBetweenCommits,
getBranches,
getRebaseSnapshot,
getRepositoryType,
} from '../../lib/git'
import { isGitOnPath } from '../../lib/is-git-on-path'
import {
Expand Down Expand Up @@ -122,6 +121,7 @@ import { UnreachableCommitsTab } from '../history/unreachable-commits-dialog'
import { sendNonFatalException } from '../../lib/helpers/non-fatal-exception'
import { SignInResult } from '../../lib/stores/sign-in-store'
import { ICustomIntegration } from '../../lib/custom-integration'
import { dirname, isAbsolute } from 'path'

/**
* An error handler function.
Expand Down Expand Up @@ -1768,6 +1768,11 @@ export class Dispatcher {
}

if (filepath !== null) {
if (isAbsolute(filepath)) {
log.error(`Refusing to open absolute path: ${filepath}`)
return
}

const resolved = await resolveWithin(repository.path, filepath)

if (resolved !== null) {
Expand Down Expand Up @@ -1881,23 +1886,26 @@ export class Dispatcher {
// user may accidentally provide a folder within the repository
// this ensures we use the repository root, if it is actually a repository
// otherwise we consider it an untracked repository
const path = await getRepositoryType(action.path)
.then(t =>
t.kind === 'regular' ? t.topLevelWorkingDirectory : action.path
)
.catch(e => {
log.error('Could not determine repository type', e)
return action.path
})

const { repositories } = this.appStore.getState()
const existingRepository = matchExistingRepository(repositories, path)

if (existingRepository) {
await this.selectRepository(existingRepository)
this.statsStore.recordAddExistingRepository()
let repo
let path = action.path

while (!(repo = matchExistingRepository(repositories, path))) {
const parent = dirname(path)
if (parent === path) {
break
}
path = parent
}

if (repo) {
await this.selectRepository(repo)
} else {
await this.showPopup({ type: PopupType.AddRepository, path })
await this.showPopup({
type: PopupType.AddRepository,
path: action.path,
})
}
break

Expand Down

0 comments on commit b115199

Please sign in to comment.