Skip to content

Refactor git.HomeDir to strict mode (report fatal when it's not initialized correctly) #19938

Closed
@wxiaoguang

Description

@wxiaoguang

At the moment, it's impossible to make the git.HomeDir work in strict mode, for unknown reasons (ref: #19930)

If git.HomeDir calls log.Fatal when it's not initialized, some integration tests fails.
https://drone.gitea.io/go-gitea/gitea/55939/3/7

This problem should be fixed in new PRs, to make sure git module always be initialized correctly.

=== TestRepoLanguages (integrations/git_helper_for_declarative_test.go:95)
--- FAIL: TestRepoLanguages (1.65s)
    testlogger.go:78: 2022/06/11 04:50:14 ...eb/routing/logger.go:99:func1() [I] [62a41f06-15] router: completed GET /user2/repo1/_new/master/ for , 200 OK in 46.9ms @ repo/editor.go:184(repo.NewFile)
    testlogger.go:78: 2022/06/11 04:50:14 ...eb/routing/logger.go:99:func1() [I] [62a41f06-27] router: completed POST /api/internal/hook/pre-receive/user2/repo1 for 127.0.0.1:57948, 200 OK in 7.8ms @ private/hook_pre_receive.go:106(private.HookPreReceive)
    testlogger.go:78: 2022/06/11 04:50:14 ...eb/routing/logger.go:99:func1() [I] [62a41f06-17] router: completed POST /user2/repo1/_new/master/ for , 303 See Other in 401.9ms @ repo/editor.go:344(repo.NewFilePost)
    testlogger.go:78: 2022/06/11 04:50:15 ...eb/routing/logger.go:99:func1() [I] [62a41f07] router: completed GET /api/v1/repos/user2/repo1/languages for , 200 OK in 6.5ms @ repo/language.go:48(repo.GetLanguages)
    api_repo_languages_test.go:48: 
        	Error Trace:	api_repo_languages_test.go:48
        	            				git_helper_for_declarative_test.go:96
        	            				git_helper_for_declarative_test.go:91
        	            				git_helper_for_declarative_test.go:95
        	            				api_repo_languages_test.go:17
        	Error:      	Arguments must have the same number of keys
        	Test:       	TestRepoLanguages
        --- FAIL: TestGit/HTTP/PushCreate (1.29s)
            testlogger.go:78: 2022/06/11 04:54:05 ...eb/routing/logger.go:99:func1() [I] [62a41fed-8] router: completed GET /user2/repo-tmp-push-create-http.git/info/refs?service=git-receive-pack for 127.0.0.1:58168, 401 Unauthorized in 3.9ms @ repo/http.go:531(repo.GetInfoRefs)
            testlogger.go:78: 2022/06/11 04:54:05 ...eb/routing/logger.go:99:func1() [I] [62a41fed-9] router: completed GET /user2/repo-tmp-push-create-http.git/info/refs?service=git-receive-pack for 127.0.0.1:58168, 403 Forbidden in 200.4ms @ repo/http.go:531(repo.GetInfoRefs)
            testlogger.go:78: 2022/06/11 04:54:05 ...eb/routing/logger.go:99:func1() [I] [62a41fed-11] router: completed GET /user2/repo-tmp-push-create-http.git/info/refs?service=git-upload-pack for 127.0.0.1:58170, 401 Unauthorized in 3.5ms @ repo/http.go:531(repo.GetInfoRefs)
            testlogger.go:78: 2022/06/11 04:54:06 ...eb/routing/logger.go:99:func1() [I] [62a41fed-12] router: completed GET /user2/repo-tmp-push-create-http.git/info/refs?service=git-upload-pack for 127.0.0.1:58170, 404 Not Found in 200.4ms @ repo/http.go:531(repo.GetInfoRefs)
            testlogger.go:78: 2022/06/11 04:54:06 ...eb/routing/logger.go:99:func1() [I] [62a41fee-2] router: completed GET /user2/repo-tmp-push-create-http.git/info/refs?service=git-receive-pack for 127.0.0.1:58172, 401 Unauthorized in 3.8ms @ repo/http.go:531(repo.GetInfoRefs)
            testlogger.go:78: 2022/06/11 04:54:06 ...eb/routing/logger.go:99:func1() [I] [62a41fee-3] router: completed GET /user2/repo-tmp-push-create-http.git/info/refs?service=git-receive-pack for 127.0.0.1:58172, 200 OK in 209.2ms @ repo/http.go:531(repo.GetInfoRefs)
            testlogger.go:78: 2022/06/11 04:54:06 ...eb/routing/logger.go:99:func1() [I] [62a41fee-11] router: completed POST /api/internal/hook/pre-receive/user2/repo-tmp-push-create-http for 127.0.0.1:58174, 200 OK in 8.0ms @ private/hook_pre_receive.go:106(private.HookPreReceive)
            testlogger.go:78: 2022/06/11 04:54:06 ...eb/routing/logger.go:99:func1() [I] [62a41fee-6] router: completed POST /user2/repo-tmp-push-create-http.git/git-receive-pack for 127.0.0.1:58172, 200 OK in 573.4ms @ repo/http.go:499(repo.ServiceReceivePack)
            git_test.go:595: 
                	Error Trace:	git_test.go:595
                	Error:      	Should be false
                	Test:       	TestGit/HTTP/PushCreate
--- FAIL: TestPullMerge (2.69s)
    testlogger.go:78: 2022/06/11 04:57:31 ...eb/routing/logger.go:99:func1() [I] router: completed POST /user2/repo1/pulls/6/merge for , 303 See Other in 613.0ms @ repo/pull.go:885(repo.MergePullRequest)
    pull_merge_test.go:86: 
        	Error Trace:	pull_merge_test.go:86
        	            				git_helper_for_declarative_test.go:96
        	            				git_helper_for_declarative_test.go:91
        	            				git_helper_for_declarative_test.go:95
        	            				pull_merge_test.go:69

        	Error:      	"[%!s(*webhook.HookTask=&{1 1 1 uuid1 <nil>   true 0 1970-01-01 00:00:00 UTC false  <nil>  <nil>})]" should have 2 item(s), but has 1
        	Test:       	TestPullMerge
--- FAIL: TestPullRebase (2.70s)

    testlogger.go:78: 2022/06/11 04:57:31 ...es/pull/temp_repo.go:117:createTemporaryRepo() [E] [62a420bb-47] Unable to fetch origin base branch [user2/repo1:master -> base, original_base in /drone/src/integrations/gitea-integration-sqlite/data/integrations/gitea-integration-sqlite/tmp/local-repo/pull.git169687650]: exit status 128:

        	fatal: '/tmp/tmp.zvcOK53rAu/integrations/gitea-integration-sqlite/gitea-repositories/user2/repo1.git' does not appear to be a git repository
        	fatal: Could not read from remote repository.

        	Please make sure you have the correct access rights
        	and the repository exists.

    testlogger.go:78: 2022/06/11 04:57:31 ...rvices/pull/patch.go:64:TestPatch() [E] [62a420bb-47] CreateTemporaryPath: Unable to fetch origin base branch [user2/repo1:master -> base, original_base in tmpBasePath]: exit status 128

        	fatal: '/tmp/tmp.zvcOK53rAu/integrations/gitea-integration-sqlite/gitea-repositories/user2/repo1.git' does not appear to be a git repository
        	fatal: Could not read from remote repository.

        	Please make sure you have the correct access rights
        	and the repository exists.

    testlogger.go:78: 2022/06/11 04:57:31 ...rvices/pull/check.go:341:testPR() [E] testPatch[2]: Unable to fetch origin base branch [user2/repo1:master -> base, original_base in tmpBasePath]: exit status 128

        	fatal: '/tmp/tmp.zvcOK53rAu/integrations/gitea-integration-sqlite/gitea-repositories/user2/repo1.git' does not appear to be a git repository
        	fatal: Could not read from remote repository.

        	Please make sure you have the correct access rights
        	and the repository exists.
--- FAIL: TestPushDeployKeyOnEmptyRepo (8.13s)
   testlogger.go:78: 2022/06/11 04:58:50 ...eb/routing/logger.go:99:func1() [I] [62a4210a-11] router: completed GET /api/v1/repos/user2/deploy-key-empty-repo-1?token=037da467132d3d8120015afa8fad0f5d505cfcf1 for , 200 OK in 209.3ms @ repo/repo.go:502(repo.Get)
    --- FAIL: TestPushDeployKeyOnEmptyRepo/CheckIsNotEmpty (0.21s)
        ssh_key_test.go:25: 
            	Error Trace:	ssh_key_test.go:25
            	            				api_helper_for_declarative_test.go:146
            	Error:      	Not equal: 
            	            	expected: false
            	            	actual  : true
            	Test:       	TestPushDeployKeyOnEmptyRepo/CheckIsNotEmpty

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions