Skip to content

Commit a727324

Browse files
committed
add "git-lfs not installed" error
1 parent 3f02813 commit a727324

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

models/error.go

+14
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ func (err ErrNamePatternNotAllowed) Error() string {
5656
return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
5757
}
5858

59+
// ErrLFSNotInstalled represents an "git-lfs not found" error.
60+
type ErrLFSNotInstalled struct {
61+
}
62+
63+
// IsLFSNotInstalled checks if an error is an ErrLFSNotInstalled.
64+
func IsLFSNotInstalled(err error) bool {
65+
_, ok := err.(ErrLFSNotInstalled)
66+
return ok
67+
}
68+
69+
func (err ErrLFSNotInstalled) Error() string {
70+
return "git-lfs not found"
71+
}
72+
5973
// ErrNameCharsNotAllowed represents a "character not allowed in name" error.
6074
type ErrNameCharsNotAllowed struct {
6175
Name string

models/repo.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"net"
1919
"net/url"
2020
"os"
21+
"os/exec"
2122
"path"
2223
"path/filepath"
2324
"sort"
@@ -935,7 +936,7 @@ func (repo *Repository) CloneLink() (cl *CloneLink) {
935936
}
936937

937938
// CheckCreateRepository check if could created a repository
938-
func CheckCreateRepository(doer, u *User, name string, overwriteOrAdopt bool) error {
939+
func CheckCreateRepository(doer, u *User, name string, lfs bool, overwriteOrAdopt bool) error {
939940
if !doer.CanCreateRepo() {
940941
return ErrReachLimitOfRepo{u.MaxRepoCreation}
941942
}
@@ -959,6 +960,12 @@ func CheckCreateRepository(doer, u *User, name string, overwriteOrAdopt bool) er
959960
if !overwriteOrAdopt && isExist {
960961
return ErrRepoFilesAlreadyExist{u.Name, name}
961962
}
963+
964+
if lfs {
965+
if _, err := exec.LookPath("git-lfs"); err != nil {
966+
return ErrLFSNotInstalled{}
967+
}
968+
}
962969
return nil
963970
}
964971

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ user_not_exist = The user does not exist.
392392
team_not_exist = The team does not exist.
393393
last_org_owner = You cannot remove the last user from the 'owners' team. There must be at least one owner for an organization.
394394
cannot_add_org_to_team = An organization cannot be added as a team member.
395+
lfs_not_installed = Please <a rel="noreferrer" href="https://git-lfs.github.com">install</a> git-lfs.
395396
396397
invalid_ssh_key = Can not verify your SSH key: %s
397398
invalid_gpg_key = Can not verify your GPG key: %s

routers/repo/migrate.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ func handleMigrateError(ctx *context.Context, owner *models.User, err error, nam
101101
case models.IsErrNamePatternNotAllowed(err):
102102
ctx.Data["Err_RepoName"] = true
103103
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
104+
case models.IsLFSNotInstalled(err):
105+
ctx.Data["Err_LFSNotInstalled"] = true
106+
ctx.RenderWithErr(ctx.Tr("form.lfs_not_installed"), tpl, form)
104107
default:
105108
remoteAddr, _ := auth.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword, owner)
106109
err = util.URLSanitizedError(err, remoteAddr)
@@ -194,7 +197,7 @@ func MigratePost(ctx *context.Context) {
194197
opts.Releases = false
195198
}
196199

197-
err = models.CheckCreateRepository(ctx.User, ctxUser, opts.RepoName, false)
200+
err = models.CheckCreateRepository(ctx.User, ctxUser, opts.RepoName, opts.LFS, false)
198201
if err != nil {
199202
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, form)
200203
return

0 commit comments

Comments
 (0)