mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
refactor(git): replace git stderr matching with exit codes (#39866)
Matching git's stderr text is fragile because it breaks silently when git rewords a message. Where git offers an exit code or a query with a defined answer, use that instead, and drop matches that could never trigger. Follow-up to the discussion in https://github.com/go-gitea/gitea/pull/39857. - Detect a missing remote by `git remote` exit code 2 - Resolve annotated tags to their tree with cat-file `^{tree}` instead of spawning `ls-tree` when listing tree entries - Skip the wiki page lookup when the default branch doesn't exist yet - Remove unreachable "no merge base" and "unknown revision" checks
This commit is contained in:
1 parent
52eb515751
commit
738ff1d65a
12 files changed
+57
-92
No files matched your search
@@ -95,14 +95,10 @@ const (
|
||||
StderrNoSuchPath StderrPrefix = "fatal: no such path"
|
||||
StderrBadObject StderrPrefix = "fatal: bad object "
|
||||
|
||||
StderrNoSuchRemote StderrPrefix = "error: no such remote"
|
||||
|
||||
StderrAuthenticationFailed StderrPrefix = "fatal: Authentication failed for"
|
||||
StderrCouldNotReadUsername StderrPrefix = "fatal: could not read Username"
|
||||
|
||||
StderrUnknownRevisionOrPath StderrRegexp = "^fatal: .*: unknown revision or path not in the working tree"
|
||||
StderrNoMergeBase StderrRegexp = "^fatal: .*: no merge base"
|
||||
StderrFileNoEnoughLines StderrRegexp = `^fatal: file .* has only \d+ lines?`
|
||||
StderrFileNoEnoughLines StderrRegexp = `^fatal: file .* has only \d+ lines?`
|
||||
)
|
||||
|
||||
func matchStderrCheck(stderr string, checkIntf StderrCheck) (match bool) {
|
||||
|
||||
@@ -14,8 +14,6 @@ func TestIsStderr(t *testing.T) {
|
||||
check StderrCheck
|
||||
stderr string
|
||||
}{
|
||||
{StderrUnknownRevisionOrPath, "fatal: ambiguous argument 'origin': unknown revision or path not in the working tree...."},
|
||||
{StderrNoMergeBase, "fatal: origin/main..HEAD: no merge base...."},
|
||||
{StderrFileNoEnoughLines, "fatal: file foo/bar has only 1 line"},
|
||||
{StderrAuthenticationFailed, "Cloning into 'repo'...\r\nremote: Invalid username or token.\r\nfatal: Authentication failed for 'https://host/repo.git/'\r\n"},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user