History

Move some code into models/git (#19879)

* Move access and repo permission to models/perm/access * fix test * Move some git related files into sub package models/git * Fix build * fix git test * move lfs to sub package * move more git related functions to models/git * Move functions sequence * Some improvements per @KN4CK3R and @delvh

Lunny Xiao committed 4 years ago

Commit 110fc571 parent a9dc9b067 files · +549 −495Browse files

Showing the changes to models/error.go (1 of 67 files). Show all

Unified · Split

models/error.go+0−78
@@ -8,7 +8,6 @@ package models · 7 unmodified lines
8import (8import (
9 "fmt"9 "fmt"
10 10
11 "code.gitea.io/gitea/models/perm"
12 repo_model "code.gitea.io/gitea/models/repo"11 repo_model "code.gitea.io/gitea/models/repo"
13 "code.gitea.io/gitea/modules/git"12 "code.gitea.io/gitea/modules/git"
14)13)
@@ -145,83 +144,6 @@ func (err ErrAccessTokenEmpty) Error() string { · 130 unmodified lines
145 return "access token is empty"144 return "access token is empty"
146}145}
147 146
148//.____ ____________________
149//| | \_ _____/ _____/
150//| | | __) \_____ \
151//| |___| \ / \
152//|_______ \___ / /_______ /
153// \/ \/ \/
154
155// ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error.
156type ErrLFSLockNotExist struct {
157 ID int64
158 RepoID int64
159 Path string
160}
161
162// IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist.
163func IsErrLFSLockNotExist(err error) bool {
164 _, ok := err.(ErrLFSLockNotExist)
165 return ok
166}
167
168func (err ErrLFSLockNotExist) Error() string {
169 return fmt.Sprintf("lfs lock does not exist [id: %d, rid: %d, path: %s]", err.ID, err.RepoID, err.Path)
170}
171
172// ErrLFSUnauthorizedAction represents a "LFSUnauthorizedAction" kind of error.
173type ErrLFSUnauthorizedAction struct {
174 RepoID int64
175 UserName string
176 Mode perm.AccessMode
177}
178
179// IsErrLFSUnauthorizedAction checks if an error is a ErrLFSUnauthorizedAction.
180func IsErrLFSUnauthorizedAction(err error) bool {
181 _, ok := err.(ErrLFSUnauthorizedAction)
182 return ok
183}
184
185func (err ErrLFSUnauthorizedAction) Error() string {
186 if err.Mode == perm.AccessModeWrite {
187 return fmt.Sprintf("User %s doesn't have write access for lfs lock [rid: %d]", err.UserName, err.RepoID)
188 }
189 return fmt.Sprintf("User %s doesn't have read access for lfs lock [rid: %d]", err.UserName, err.RepoID)
190}
191
192// ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error.
193type ErrLFSLockAlreadyExist struct {
194 RepoID int64
195 Path string
196}
197
198// IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist.
199func IsErrLFSLockAlreadyExist(err error) bool {
200 _, ok := err.(ErrLFSLockAlreadyExist)
201 return ok
202}
203
204func (err ErrLFSLockAlreadyExist) Error() string {
205 return fmt.Sprintf("lfs lock already exists [rid: %d, path: %s]", err.RepoID, err.Path)
206}
207
208// ErrLFSFileLocked represents a "LFSFileLocked" kind of error.
209type ErrLFSFileLocked struct {
210 RepoID int64
211 Path string
212 UserName string
213}
214
215// IsErrLFSFileLocked checks if an error is a ErrLFSFileLocked.
216func IsErrLFSFileLocked(err error) bool {
217 _, ok := err.(ErrLFSFileLocked)
218 return ok
219}
220
221func (err ErrLFSFileLocked) Error() string {
222 return fmt.Sprintf("File is lfs locked [repo: %d, locked by: %s, path: %s]", err.RepoID, err.UserName, err.Path)
223}
224
225// ErrNoPendingRepoTransfer is an error type for repositories without a pending147// ErrNoPendingRepoTransfer is an error type for repositories without a pending
226// transfer request148// transfer request
227type ErrNoPendingRepoTransfer struct {149type ErrNoPendingRepoTransfer struct {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t