mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: ignore empty branch from branch selector element
This commit is contained in:
parent
b606a4bb7d
commit
16cfcd7200
1 changed files with 13 additions and 1 deletions
|
|
@ -10,6 +10,7 @@ import { embeddedDataStruct } from './embeddedDataStructures'
|
|||
const selectors = {
|
||||
normal: {
|
||||
reactApp: `react-app[app-name="react-code-view"] [data-target="react-app.reactRoot"]`,
|
||||
codeTab: '#code-tab',
|
||||
branchSwitcher: [`summary[title="Switch branches or tags"]`, `#branch-select-menu`].join(),
|
||||
fileNavigation: `.file-navigation`,
|
||||
breadcrumbs: `[data-testid="breadcrumbs"]`,
|
||||
|
|
@ -160,7 +161,7 @@ export function getCurrentBranch(passive = false) {
|
|||
}
|
||||
const defaultTitle = 'Switch branches or tags'
|
||||
const title = branchButtonElement.title.trim()
|
||||
if (title !== defaultTitle && !title.includes(' ')) return title
|
||||
if (title && title !== defaultTitle && !title.includes(' ')) return title
|
||||
}
|
||||
|
||||
const findFileButtonSelector = 'main .file-navigation a[data-hotkey="t"]'
|
||||
|
|
@ -177,6 +178,17 @@ export function getCurrentBranch(passive = false) {
|
|||
}
|
||||
}
|
||||
|
||||
const branchNameFromCodeTab = $(selectors.normal.codeTab, e => {
|
||||
if (e instanceof HTMLAnchorElement) {
|
||||
const chunks = e.href.split('/')
|
||||
const indexOfTree = chunks.indexOf('tree')
|
||||
if (indexOfTree === -1) return
|
||||
const branchName = chunks.slice(indexOfTree + 1).join('/')
|
||||
return branchName
|
||||
}
|
||||
})
|
||||
if (branchNameFromCodeTab) return branchNameFromCodeTab
|
||||
|
||||
if (!passive) raiseError(new Error('cannot get current branch'))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue