Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

500 Error in Empty repository #8538

Closed
1 of 7 tasks
RelicOfTesla opened this issue Oct 16, 2019 · 4 comments · Fixed by #8539
Closed
1 of 7 tasks

500 Error in Empty repository #8538

RelicOfTesla opened this issue Oct 16, 2019 · 4 comments · Fixed by #8539
Labels
Milestone

Comments

@RelicOfTesla
Copy link

RelicOfTesla commented Oct 16, 2019

  • Gitea version (or commit ref): 1.10rc1 ref: db0d4ff
  • Git version:
  • Operating system: win7
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

step1. New/Create Repository
step2. http://xxxxx:3000/xxxx/xxxx/issues/new
or /xxxx/xxxx/settings/hooks/git
response 500 error

...

Screenshots

@zeripath
Copy link
Contributor

It would be helpful to get the log in cases like this, however it appears simple to replicate.

When trying the /issues/new endpoint I get:

2019/10/16 10:20:54 ...les/context/panic.go:35:1() [E] PANIC:: runtime error: invalid memory address or nil pointer dereference
	/usr/lib/go-1.13/src/runtime/panic.go:199 (0x452b4b)
		panicmem: panic(memoryError)
	/usr/lib/go-1.13/src/runtime/signal_unix.go:394 (0x452988)
		sigpanic: panicmem()
	/home/andrew/go/src/code.gitea.io/gitea/modules/git/repo_commit.go:22 (0x954e85)
		(*Repository).GetRefCommitID: ref, err := repo.gogitRepo.Reference(plumbing.ReferenceName(name), true)
	/home/andrew/go/src/code.gitea.io/gitea/modules/git/repo_commit.go:39 (0x9565c8)
		(*Repository).GetBranchCommitID: return repo.GetRefCommitID(BranchPrefix + name)
	/home/andrew/go/src/code.gitea.io/gitea/modules/git/repo_commit.go:149 (0x956571)
		(*Repository).GetBranchCommit: commitID, err := repo.GetBranchCommitID(name)
	/home/andrew/go/src/code.gitea.io/gitea/routers/repo/issue.go:385 (0x125c0d3)
		getFileContentFromDefaultBranch: ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
	/home/andrew/go/src/code.gitea.io/gitea/routers/repo/issue.go:412 (0x125c1cb)
		setTemplateIfExists: content, found := getFileContentFromDefaultBranch(ctx, filename)
	/home/andrew/go/src/code.gitea.io/gitea/routers/repo/issue.go:442 (0x125c717)
		NewIssue: setTemplateIfExists(ctx, issueTemplateKey, IssueTemplateCandidates)
	/usr/lib/go-1.13/src/reflect/value.go:460 (0x49dea5)
	...

And on /settings/hook/git:

2019/10/16 10:22:31 ...les/context/panic.go:35:1() [E] PANIC:: runtime error: invalid memory address or nil pointer dereference
	/usr/lib/go-1.13/src/runtime/panic.go:199 (0x452b4b)
		panicmem: panic(memoryError)
	/usr/lib/go-1.13/src/runtime/signal_unix.go:394 (0x452988)
		sigpanic: panicmem()
	/home/andrew/go/src/code.gitea.io/gitea/routers/repo/setting.go:685 (0x1297406)
		GitHooks: hooks, err := ctx.Repo.GitRepo.Hooks()
	/home/andrew/go/src/code.gitea.io/gitea/routers/repo/setting.go:685 (0x12973fa)
		GitHooks: hooks, err := ctx.Repo.GitRepo.Hooks()
	/usr/lib/go-1.13/src/reflect/value.go:460 (0x49dea5)
		Value.call: call(frametype, fn, args, uint32(frametype.size), uint32(retOffset))
	/usr/lib/go-1.13/src/reflect/value.go:321 (0x49d663)
		Value.Call: return v.call("Call", in)
	/home/andrew/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:177 (0x9b1d79)
		(*injector).callInvoke: return reflect.ValueOf(f).Call(in), nil
	/home/andrew/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:137 (0x9b1729)
		(*injector).Invoke: return inj.callInvoke(f, t, t.NumIn())
	/home/andrew/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0x9e18c8)
		(*Context).run: vals, err := c.Invoke(c.handler())
	/home/andrew/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0x10db6d1)
		(*Context).Next: c.run()

@zeripath
Copy link
Contributor

So the problem is that either ctx.Repo.GitRepo is nil or ctx.Repo is nil.

@zeripath
Copy link
Contributor

// repo is empty and display enable
if ctx.Repo.Repository.IsEmpty || ctx.Repo.Repository.IsBeingCreated() {
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
return
}
gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName))
if err != nil {
ctx.ServerError("RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err)
return
}
ctx.Repo.GitRepo = gitRepo

Implies that in an empty repo - ctx.Repo.GitRepo will be nil

@zeripath
Copy link
Contributor

Simplest Solution:

  • Separate out the IsEmpty and BeingCreated bits - as I think it's possible that opening a git repo in creation would fail.
  • Return on IsEmpty after setting the gitRepo

zeripath added a commit to zeripath/gitea that referenced this issue Oct 16, 2019
Both issues/new and settings/hooks/git expect `ctx.Repo.GitRepo` to be set.
This PR changes the context code to open the GitRepo.

Fixes go-gitea#8538
@lunny lunny added the type/bug label Oct 16, 2019
@lunny lunny added this to the 1.10.0 milestone Oct 16, 2019
lafriks pushed a commit that referenced this issue Oct 16, 2019
Both issues/new and settings/hooks/git expect `ctx.Repo.GitRepo` to be set.
This PR changes the context code to open the GitRepo.

Fixes #8538
zeripath added a commit to zeripath/gitea that referenced this issue Oct 16, 2019
Both issues/new and settings/hooks/git expect `ctx.Repo.GitRepo` to be set.
This PR changes the context code to open the GitRepo.

Fixes go-gitea#8538
lunny pushed a commit that referenced this issue Oct 16, 2019
Both issues/new and settings/hooks/git expect `ctx.Repo.GitRepo` to be set.
This PR changes the context code to open the GitRepo.

Fixes #8538
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants