Skip to content

Commit 0193b79

Browse files
committed
fix
1 parent f365a6b commit 0193b79

4 files changed

Lines changed: 48 additions & 29 deletions

File tree

‎models/issues/pull.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"gitea.dev/modules/util"
2626

2727
"github.com/dlclark/regexp2/v2"
28+
"github.com/kballard/go-shellquote"
2829
"xorm.io/builder"
2930
)
3031

@@ -407,6 +408,21 @@ func (pr *PullRequest) GetGitHeadRefName() string { // TODO: make it return RefN
407408
return git.RefNameFromPullIndex(pr.Index).String()
408409
}
409410

411+
func (pr *PullRequest) GetBranchCliArgs() (ret struct {
412+
BaseBranchArg string
413+
HeadBranchArg string
414+
LocalBranchArg string
415+
},
416+
) {
417+
ret.BaseBranchArg = shellquote.Join(pr.BaseBranch)
418+
ret.HeadBranchArg = shellquote.Join(pr.HeadBranch)
419+
ret.LocalBranchArg = ret.HeadBranchArg
420+
if pr.HeadRepo != nil && pr.HeadRepoID != pr.BaseRepoID {
421+
ret.LocalBranchArg = shellquote.Join(pr.HeadRepo.OwnerName) + "-" + ret.HeadBranchArg
422+
}
423+
return ret
424+
}
425+
410426
// GetReviewCommentsCount returns the number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR)
411427
func (pr *PullRequest) GetReviewCommentsCount(ctx context.Context) int {
412428
opts := FindCommentsOptions{

‎services/repository/gitgraph/graph.go‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ import (
77
"bufio"
88
"bytes"
99
"context"
10+
"strings"
1011

1112
"gitea.dev/modules/git"
1213
"gitea.dev/modules/git/gitcmd"
1314
"gitea.dev/modules/setting"
1415
)
1516

17+
const gitLogGraphFormatSep = "^" // disallowed char in git ref names
18+
1619
// GetCommitGraph return a list of commit (GraphItems) from all branches
1720
func GetCommitGraph(ctx context.Context, gitRepo *git.Repository, page, maxAllowedColors int, hidePRRefs bool, refs, files []string) (*Graph, error) {
18-
format := "DATA:%D|%H|%ad|%h|%s"
19-
20-
if page == 0 {
21-
page = 1
22-
}
21+
format := "DATA:" + strings.Join([]string{
22+
"%D", // ref names without the " (", ")" wrapping.
23+
"%H", // commit hash
24+
"%ad", // author date (format respects --date= option)
25+
"%h", // abbreviated commit hash
26+
"%s", // subject
27+
}, gitLogGraphFormatSep)
2328

29+
page = max(page, 1)
2430
graphCmd := gitcmd.NewCommand("log", "--graph", "--date-order", "--decorate=full")
2531

2632
if hidePRRefs {
@@ -31,7 +37,7 @@ func GetCommitGraph(ctx context.Context, gitRepo *git.Repository, page, maxAllow
3137
graphCmd.AddArguments("--tags", "--branches")
3238
}
3339

34-
graphCmd.AddArguments("-C", "-M", "--date=iso-strict").
40+
graphCmd.AddArguments("--find-copies", "--find-renames", "--date=iso-strict").
3541
AddOptionFormat("-n %d", setting.UI.GraphMaxCommitNum*page).
3642
AddOptionFormat("--pretty=format:%s", format)
3743

‎services/repository/gitgraph/graph_models.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func parseGitTime(timeStr string) time.Time {
216216

217217
// NewCommit creates a new commit from a provided line
218218
func NewCommit(row, column int, line []byte) (*Commit, error) {
219-
data := bytes.SplitN(line, []byte("|"), 5)
219+
data := bytes.SplitN(line, []byte(gitLogGraphFormatSep), 5)
220220
if len(data) < 5 {
221221
return nil, fmt.Errorf("malformed data section on line %d with commit: %s", row, string(line))
222222
}

‎templates/repo/issue/view_content/pull_merge_instruction.tmpl‎

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@
99
<h3 class="tw-m-0">{{ctx.Locale.Tr "repo.pulls.cmd_instruction_checkout_title"}}</h3>
1010
{{ctx.Locale.Tr "repo.pulls.cmd_instruction_checkout_desc"}}
1111
</div>
12-
{{$localBranch := $pull.HeadBranch}}
13-
{{if ne $pull.HeadRepo.ID $pull.BaseRepo.ID}}
14-
{{$localBranch = print $pull.HeadRepo.OwnerName "-" $pull.HeadBranch}}
15-
{{end}}
12+
{{$args := $pull.GetBranchCliArgs}}
1613
<div class="ui secondary segment tw-font-mono">
1714
{{$gitRemoteName := ctx.RootData.SystemConfig.Repository.GitGuideRemoteName.Value ctx}}
1815
{{if eq $pull.Flow 0}}
19-
<div>git fetch -u {{if ne $pull.HeadRepo.ID $pull.BaseRepo.ID}}{{$pull.HeadRepo.HTMLURL ctx}}{{else}}{{$gitRemoteName}}{{end}} {{$pull.HeadBranch}}:{{$localBranch}}</div>
16+
<div>git fetch -u {{if ne $pull.HeadRepo.ID $pull.BaseRepo.ID}}{{$pull.HeadRepo.HTMLURL ctx}}{{else}}{{$gitRemoteName}}{{end}} {{$args.HeadBranchArg}}:{{$args.LocalBranchArg}}</div>
2017
{{else}}
21-
<div>git fetch -u {{$gitRemoteName}} {{$pull.GetGitHeadRefName}}:{{$localBranch}}</div>
18+
<div>git fetch -u {{$gitRemoteName}} {{$args.HeadBranchArg}}:{{$args.LocalBranchArg}}</div>
2219
{{end}}
23-
<div>git checkout {{$localBranch}}</div>
20+
<div>git checkout {{$args.LocalBranchArg}}</div>
2421
</div>
2522
{{if $data.ShowMergeInstructions}}
2623
<div>
@@ -32,32 +29,32 @@
3229
</div>
3330
<div class="ui secondary segment tw-font-mono">
3431
<div data-pull-merge-style="merge">
35-
<div>git checkout {{$pull.BaseBranch}}</div>
36-
<div>git merge --no-ff {{$localBranch}}</div>
32+
<div>git checkout {{$args.BaseBranchArg}}</div>
33+
<div>git merge --no-ff {{$args.LocalBranchArg}}</div>
3734
</div>
3835
<div class="tw-hidden" data-pull-merge-style="rebase">
39-
<div>git checkout {{$pull.BaseBranch}}</div>
40-
<div>git merge --ff-only {{$localBranch}}</div>
36+
<div>git checkout {{$args.BaseBranchArg}}</div>iv>
37+
<div>git merge --ff-only {{$args.LocalBranchArg}}</div>
4138
</div>
4239
<div class="tw-hidden" data-pull-merge-style="rebase-merge">
43-
<div>git checkout {{$localBranch}}</div>
44-
<div>git rebase {{$pull.BaseBranch}}</div>
45-
<div>git checkout {{$pull.BaseBranch}}</div>
46-
<div>git merge --no-ff {{$localBranch}}</div>
40+
<div>git checkout {{$args.LocalBranchArg}}</div>
41+
<div>git rebase {{$args.BaseBranchArg}}</div>
42+
<div>git checkout {{$args.BaseBranchArg}}</div>
43+
<div>git merge --no-ff {{$args.LocalBranchArg}}</div>
4744
</div>
4845
<div class="tw-hidden" data-pull-merge-style="squash">
49-
<div>git checkout {{$pull.BaseBranch}}</div>
50-
<div>git merge --squash {{$localBranch}}</div>
46+
<div>git checkout {{$args.BaseBranchArg}}</div>
47+
<div>git merge --squash {{$args.LocalBranchArg}}</div>
5148
</div>
5249
<div class="tw-hidden" data-pull-merge-style="fast-forward-only">
53-
<div>git checkout {{$pull.BaseBranch}}</div>
54-
<div>git merge --ff-only {{$localBranch}}</div>
50+
<div>git checkout {{$args.BaseBranchArg}}</div>
51+
<div>git merge --ff-only {{$args.LocalBranchArg}}</div>
5552
</div>
5653
<div class="tw-hidden" data-pull-merge-style="manually-merged">
57-
<div>git checkout {{$pull.BaseBranch}}</div>
58-
<div>git merge {{$localBranch}}</div>
54+
<div>git checkout {{$args.BaseBranchArg}}</div>
55+
<div>git merge {{$args.LocalBranchArg}}</div>
5956
</div>
60-
<div>git push {{$gitRemoteName}} {{$pull.BaseBranch}}</div>
57+
<div>git push {{$gitRemoteName}} {{$args.BaseBranchArg}}</div>
6158
</div>
6259
{{end}}
6360
</div>

0 commit comments

Comments
 (0)