mirror of
https://github.com/harness/drone.git
synced 2025-05-18 18:09:56 +08:00
Disable branch creation when committing first new file into an empty repo (#217)
This commit is contained in:
parent
797e339e02
commit
92c82f5c44
@ -50,6 +50,7 @@ interface CommitModalButtonProps extends Omit<ButtonProps, 'onClick' | 'onSubmit
|
||||
gitRef: string
|
||||
resourcePath: string
|
||||
commitTitlePlaceHolder: string
|
||||
disableBranchCreation?: boolean
|
||||
oldResourcePath?: string
|
||||
payload?: string
|
||||
sha?: string
|
||||
@ -63,6 +64,7 @@ export const CommitModalButton: React.FC<CommitModalButtonProps> = ({
|
||||
resourcePath,
|
||||
commitTitlePlaceHolder,
|
||||
oldResourcePath,
|
||||
disableBranchCreation = false,
|
||||
payload = '',
|
||||
sha,
|
||||
onSuccess,
|
||||
@ -172,6 +174,7 @@ export const CommitModalButton: React.FC<CommitModalButtonProps> = ({
|
||||
)}>
|
||||
<FormInput.RadioGroup
|
||||
name="branch"
|
||||
disabled={disableBranchCreation}
|
||||
label=""
|
||||
onChange={e => {
|
||||
setTargetBranchOption(get(e.target, 'defaultValue'))
|
||||
|
@ -25,8 +25,8 @@ export function useGetResourceContent({
|
||||
lazy: !repoMetadata || lazy
|
||||
})
|
||||
const isRepositoryEmpty = useMemo(
|
||||
() => repoMetadata && error && !data && response?.status === 404,
|
||||
[repoMetadata, error, data, response]
|
||||
() => (repoMetadata && resourcePath === '' && error && response?.status === 404) || false,
|
||||
[repoMetadata, resourcePath, error, response]
|
||||
)
|
||||
|
||||
return { data, error: isRepositoryEmpty ? undefined : error, loading, refetch, response, isRepositoryEmpty }
|
||||
|
@ -15,9 +15,10 @@ import css from './FileEditor.module.scss'
|
||||
|
||||
interface EditorProps extends Pick<GitInfoProps, 'repoMetadata' | 'gitRef' | 'resourcePath'> {
|
||||
resourceContent: GitInfoProps['resourceContent'] | null
|
||||
isRepositoryEmpty: boolean
|
||||
}
|
||||
|
||||
function Editor({ resourceContent, repoMetadata, gitRef, resourcePath }: EditorProps) {
|
||||
function Editor({ resourceContent, repoMetadata, gitRef, resourcePath, isRepositoryEmpty }: EditorProps) {
|
||||
const history = useHistory()
|
||||
const inputRef = useRef<HTMLInputElement | null>()
|
||||
const isNew = useMemo(() => !resourceContent || isDir(resourceContent), [resourceContent])
|
||||
@ -200,6 +201,7 @@ function Editor({ resourceContent, repoMetadata, gitRef, resourcePath }: EditorP
|
||||
}
|
||||
setOriginalContent(content)
|
||||
}}
|
||||
disableBranchCreation={isRepositoryEmpty}
|
||||
/>
|
||||
<Button
|
||||
text={getString('cancel')}
|
||||
|
@ -35,6 +35,7 @@ export default function RepositoryFileEdit() {
|
||||
gitRef={gitRef}
|
||||
resourcePath={resourcePath}
|
||||
resourceContent={resourceContent}
|
||||
isRepositoryEmpty={isRepositoryEmpty}
|
||||
/>
|
||||
)}
|
||||
</Container>
|
||||
|
Loading…
Reference in New Issue
Block a user