Skip to content

Commit

Permalink
add "git-lfs not installed" error
Browse files Browse the repository at this point in the history
  • Loading branch information
bl00mber committed Feb 19, 2021
1 parent 3f02813 commit a727324
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
14 changes: 14 additions & 0 deletions models/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ func (err ErrNamePatternNotAllowed) Error() string {
return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
}

// ErrLFSNotInstalled represents an "git-lfs not found" error.
type ErrLFSNotInstalled struct {
}

// IsLFSNotInstalled checks if an error is an ErrLFSNotInstalled.
func IsLFSNotInstalled(err error) bool {
_, ok := err.(ErrLFSNotInstalled)
return ok
}

func (err ErrLFSNotInstalled) Error() string {
return "git-lfs not found"
}

// ErrNameCharsNotAllowed represents a "character not allowed in name" error.
type ErrNameCharsNotAllowed struct {
Name string
Expand Down
9 changes: 8 additions & 1 deletion models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"net"
"net/url"
"os"
"os/exec"
"path"
"path/filepath"
"sort"
Expand Down Expand Up @@ -935,7 +936,7 @@ func (repo *Repository) CloneLink() (cl *CloneLink) {
}

// CheckCreateRepository check if could created a repository
func CheckCreateRepository(doer, u *User, name string, overwriteOrAdopt bool) error {
func CheckCreateRepository(doer, u *User, name string, lfs bool, overwriteOrAdopt bool) error {
if !doer.CanCreateRepo() {
return ErrReachLimitOfRepo{u.MaxRepoCreation}
}
Expand All @@ -959,6 +960,12 @@ func CheckCreateRepository(doer, u *User, name string, overwriteOrAdopt bool) er
if !overwriteOrAdopt && isExist {
return ErrRepoFilesAlreadyExist{u.Name, name}
}

if lfs {
if _, err := exec.LookPath("git-lfs"); err != nil {
return ErrLFSNotInstalled{}
}
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ user_not_exist = The user does not exist.
team_not_exist = The team does not exist.
last_org_owner = You cannot remove the last user from the 'owners' team. There must be at least one owner for an organization.
cannot_add_org_to_team = An organization cannot be added as a team member.
lfs_not_installed = Please <a rel="noreferrer" href="https://git-lfs.github.com">install</a> git-lfs.
invalid_ssh_key = Can not verify your SSH key: %s
invalid_gpg_key = Can not verify your GPG key: %s
Expand Down
5 changes: 4 additions & 1 deletion routers/repo/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ func handleMigrateError(ctx *context.Context, owner *models.User, err error, nam
case models.IsErrNamePatternNotAllowed(err):
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
case models.IsLFSNotInstalled(err):
ctx.Data["Err_LFSNotInstalled"] = true
ctx.RenderWithErr(ctx.Tr("form.lfs_not_installed"), tpl, form)
default:
remoteAddr, _ := auth.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword, owner)
err = util.URLSanitizedError(err, remoteAddr)
Expand Down Expand Up @@ -194,7 +197,7 @@ func MigratePost(ctx *context.Context) {
opts.Releases = false
}

err = models.CheckCreateRepository(ctx.User, ctxUser, opts.RepoName, false)
err = models.CheckCreateRepository(ctx.User, ctxUser, opts.RepoName, opts.LFS, false)
if err != nil {
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, form)
return
Expand Down

0 comments on commit a727324

Please sign in to comment.