|
|
@ -59,6 +59,7 @@ type Repository struct { |
|
|
|
Commit *git.Commit |
|
|
|
Commit *git.Commit |
|
|
|
Tag *git.Tag |
|
|
|
Tag *git.Tag |
|
|
|
GitRepo *git.Repository |
|
|
|
GitRepo *git.Repository |
|
|
|
|
|
|
|
RefName string |
|
|
|
BranchName string |
|
|
|
BranchName string |
|
|
|
TagName string |
|
|
|
TagName string |
|
|
|
TreePath string |
|
|
|
TreePath string |
|
|
@ -191,9 +192,9 @@ func (r *Repository) BranchNameSubURL() string { |
|
|
|
case r.IsViewBranch: |
|
|
|
case r.IsViewBranch: |
|
|
|
return "branch/" + util.PathEscapeSegments(r.BranchName) |
|
|
|
return "branch/" + util.PathEscapeSegments(r.BranchName) |
|
|
|
case r.IsViewTag: |
|
|
|
case r.IsViewTag: |
|
|
|
return "tag/" + util.PathEscapeSegments(r.BranchName) |
|
|
|
return "tag/" + util.PathEscapeSegments(r.TagName) |
|
|
|
case r.IsViewCommit: |
|
|
|
case r.IsViewCommit: |
|
|
|
return "commit/" + util.PathEscapeSegments(r.BranchName) |
|
|
|
return "commit/" + util.PathEscapeSegments(r.CommitID) |
|
|
|
} |
|
|
|
} |
|
|
|
log.Error("Unknown view type for repo: %v", r) |
|
|
|
log.Error("Unknown view type for repo: %v", r) |
|
|
|
return "" |
|
|
|
return "" |
|
|
@ -563,8 +564,6 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { |
|
|
|
ctx.Data["Branches"] = brs |
|
|
|
ctx.Data["Branches"] = brs |
|
|
|
ctx.Data["BranchesCount"] = len(brs) |
|
|
|
ctx.Data["BranchesCount"] = len(brs) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["TagName"] = ctx.Repo.TagName |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If not branch selected, try default one.
|
|
|
|
// If not branch selected, try default one.
|
|
|
|
// If default branch doesn't exists, fall back to some other branch.
|
|
|
|
// If default branch doesn't exists, fall back to some other branch.
|
|
|
|
if len(ctx.Repo.BranchName) == 0 { |
|
|
|
if len(ctx.Repo.BranchName) == 0 { |
|
|
@ -573,9 +572,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { |
|
|
|
} else if len(brs) > 0 { |
|
|
|
} else if len(brs) > 0 { |
|
|
|
ctx.Repo.BranchName = brs[0] |
|
|
|
ctx.Repo.BranchName = brs[0] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Repo.RefName = ctx.Repo.BranchName |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["BranchName"] = ctx.Repo.BranchName |
|
|
|
ctx.Data["BranchName"] = ctx.Repo.BranchName |
|
|
|
ctx.Data["CommitID"] = ctx.Repo.CommitID |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// People who have push access or have forked repository can propose a new pull request.
|
|
|
|
// People who have push access or have forked repository can propose a new pull request.
|
|
|
|
canPush := ctx.Repo.CanWrite(unit_model.TypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)) |
|
|
|
canPush := ctx.Repo.CanWrite(unit_model.TypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)) |
|
|
@ -781,7 +780,6 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context |
|
|
|
// Get default branch.
|
|
|
|
// Get default branch.
|
|
|
|
if len(ctx.Params("*")) == 0 { |
|
|
|
if len(ctx.Params("*")) == 0 { |
|
|
|
refName = ctx.Repo.Repository.DefaultBranch |
|
|
|
refName = ctx.Repo.Repository.DefaultBranch |
|
|
|
ctx.Repo.BranchName = refName |
|
|
|
|
|
|
|
if !ctx.Repo.GitRepo.IsBranchExist(refName) { |
|
|
|
if !ctx.Repo.GitRepo.IsBranchExist(refName) { |
|
|
|
brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 0) |
|
|
|
brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 0) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -795,6 +793,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context |
|
|
|
} |
|
|
|
} |
|
|
|
refName = brs[0] |
|
|
|
refName = brs[0] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Repo.RefName = refName |
|
|
|
|
|
|
|
ctx.Repo.BranchName = refName |
|
|
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName) |
|
|
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("GetBranchCommit", err) |
|
|
|
ctx.ServerError("GetBranchCommit", err) |
|
|
@ -805,7 +805,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
refName = getRefName(ctx, refType) |
|
|
|
refName = getRefName(ctx, refType) |
|
|
|
ctx.Repo.BranchName = refName |
|
|
|
ctx.Repo.RefName = refName |
|
|
|
isRenamedBranch, has := ctx.Data["IsRenamedBranch"].(bool) |
|
|
|
isRenamedBranch, has := ctx.Data["IsRenamedBranch"].(bool) |
|
|
|
if isRenamedBranch && has { |
|
|
|
if isRenamedBranch && has { |
|
|
|
renamedBranchName := ctx.Data["RenamedBranchName"].(string) |
|
|
|
renamedBranchName := ctx.Data["RenamedBranchName"].(string) |
|
|
@ -817,6 +817,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context |
|
|
|
|
|
|
|
|
|
|
|
if refType.RefTypeIncludesBranches() && ctx.Repo.GitRepo.IsBranchExist(refName) { |
|
|
|
if refType.RefTypeIncludesBranches() && ctx.Repo.GitRepo.IsBranchExist(refName) { |
|
|
|
ctx.Repo.IsViewBranch = true |
|
|
|
ctx.Repo.IsViewBranch = true |
|
|
|
|
|
|
|
ctx.Repo.BranchName = refName |
|
|
|
|
|
|
|
|
|
|
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName) |
|
|
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -827,6 +828,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context |
|
|
|
|
|
|
|
|
|
|
|
} else if refType.RefTypeIncludesTags() && ctx.Repo.GitRepo.IsTagExist(refName) { |
|
|
|
} else if refType.RefTypeIncludesTags() && ctx.Repo.GitRepo.IsTagExist(refName) { |
|
|
|
ctx.Repo.IsViewTag = true |
|
|
|
ctx.Repo.IsViewTag = true |
|
|
|
|
|
|
|
ctx.Repo.TagName = refName |
|
|
|
|
|
|
|
|
|
|
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName) |
|
|
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("GetTagCommit", err) |
|
|
|
ctx.ServerError("GetTagCommit", err) |
|
|
@ -870,6 +873,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["BranchName"] = ctx.Repo.BranchName |
|
|
|
ctx.Data["BranchName"] = ctx.Repo.BranchName |
|
|
|
ctx.Data["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL() |
|
|
|
ctx.Data["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL() |
|
|
|
|
|
|
|
ctx.Data["TagName"] = ctx.Repo.TagName |
|
|
|
ctx.Data["CommitID"] = ctx.Repo.CommitID |
|
|
|
ctx.Data["CommitID"] = ctx.Repo.CommitID |
|
|
|
ctx.Data["TreePath"] = ctx.Repo.TreePath |
|
|
|
ctx.Data["TreePath"] = ctx.Repo.TreePath |
|
|
|
ctx.Data["IsViewBranch"] = ctx.Repo.IsViewBranch |
|
|
|
ctx.Data["IsViewBranch"] = ctx.Repo.IsViewBranch |
|
|
|