diff --git a/models/action.go b/models/action.go index fa610ff5c..275914b32 100644 --- a/models/action.go +++ b/models/action.go @@ -517,7 +517,7 @@ func CommitRepoAction(opts CommitRepoActionOptions) error { } // Change repository bare status and update last updated time. - repo.IsBare = false + repo.IsBare = repo.IsBare && opts.Commits.Len <= 0 if err = UpdateRepository(repo, false); err != nil { return fmt.Errorf("UpdateRepository: %v", err) } diff --git a/modules/context/repo.go b/modules/context/repo.go index 919105f7b..545a9a3ff 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -390,6 +390,10 @@ func RepoRef() macaron.Handler { if err != nil { ctx.Handle(500, "GetBranches", err) return + } else if len(brs) == 0 { + err = fmt.Errorf("No branches in non-bare repository %s", + ctx.Repo.GitRepo.Path) + ctx.Handle(500, "GetBranches", err) } refName = brs[0] }