Skip to content

500 Error in Empty repository #8538

@RelicOfTesla

Description

@RelicOfTesla
  • 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

Activity

zeripath

zeripath commented on Oct 16, 2019

@zeripath
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

zeripath commented on Oct 16, 2019

@zeripath
Contributor

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

zeripath

zeripath commented on Oct 16, 2019

@zeripath
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

zeripath commented on Oct 16, 2019

@zeripath
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
added a commit that references this issue on Oct 16, 2019
5d5df27
added this to the 1.10.0 milestone on Oct 16, 2019
added a commit that references this issue on Oct 16, 2019
1b72690
added a commit that references this issue on Oct 16, 2019
daf764f
added a commit that references this issue on Oct 16, 2019
34b8bec
locked and limited conversation to collaborators on Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @lunny@zeripath@RelicOfTesla

      Issue actions

        500 Error in Empty repository · Issue #8538 · go-gitea/gitea