mirror of
https://github.com/go-gitea/gitea
synced 2024-10-31 23:34:25 +00:00
a5279b74b6
* Make auto check manual merge as a chooseable mod and add manual merge way on ui as title, Before this pr, we use same way with GH to check manually merge. It good, but in some special cases, misjudgments can occur. and it's hard to fix this bug. So I add option to allow repo manager block "auto check manual merge" function, Then it will have same style like gitlab(allow empty pr). and to compensate for not being able to detect THE PR merge automatically, I added a manual approach. Signed-off-by: a1012112796 <1012112796@qq.com> * make swager * api support * ping ci * fix TestPullCreate_EmptyChangesWithCommits * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * Apply review suggestions and add test * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * fix build * test error message * make fmt * Fix indentation issues identified by @silverwind Co-authored-by: silverwind <me@silverwind.io> * Fix tests and make manually merged disabled error on API the same Signed-off-by: Andrew Thornton <art27@cantab.net> * a small nit * fix wrong commit id error * fix bug * simple test * fix test Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
81 lines
2.5 KiB
Go
81 lines
2.5 KiB
Go
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package git
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRepository_GetCommitBranches(t *testing.T) {
|
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
|
bareRepo1, err := OpenRepository(bareRepo1Path)
|
|
assert.NoError(t, err)
|
|
defer bareRepo1.Close()
|
|
|
|
// these test case are specific to the repo1_bare test repo
|
|
testCases := []struct {
|
|
CommitID string
|
|
ExpectedBranches []string
|
|
}{
|
|
{"2839944139e0de9737a044f78b0e4b40d989a9e3", []string{"branch1"}},
|
|
{"5c80b0245c1c6f8343fa418ec374b13b5d4ee658", []string{"branch2"}},
|
|
{"37991dec2c8e592043f47155ce4808d4580f9123", []string{"master"}},
|
|
{"95bb4d39648ee7e325106df01a621c530863a653", []string{"branch1", "branch2"}},
|
|
{"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", []string{"branch2", "master"}},
|
|
{"master", []string{"master"}},
|
|
}
|
|
for _, testCase := range testCases {
|
|
commit, err := bareRepo1.GetCommit(testCase.CommitID)
|
|
assert.NoError(t, err)
|
|
branches, err := bareRepo1.getBranches(commit, 2)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, testCase.ExpectedBranches, branches)
|
|
}
|
|
}
|
|
|
|
func TestGetTagCommitWithSignature(t *testing.T) {
|
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
|
bareRepo1, err := OpenRepository(bareRepo1Path)
|
|
assert.NoError(t, err)
|
|
defer bareRepo1.Close()
|
|
|
|
commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a")
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, commit)
|
|
assert.NotNil(t, commit.Signature)
|
|
// test that signature is not in message
|
|
assert.Equal(t, "tag", commit.CommitMessage)
|
|
}
|
|
|
|
func TestGetCommitWithBadCommitID(t *testing.T) {
|
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
|
bareRepo1, err := OpenRepository(bareRepo1Path)
|
|
assert.NoError(t, err)
|
|
defer bareRepo1.Close()
|
|
|
|
commit, err := bareRepo1.GetCommit("bad_branch")
|
|
assert.Nil(t, commit)
|
|
assert.Error(t, err)
|
|
assert.True(t, IsErrNotExist(err))
|
|
}
|
|
|
|
func TestIsCommitInBranch(t *testing.T) {
|
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
|
bareRepo1, err := OpenRepository(bareRepo1Path)
|
|
assert.NoError(t, err)
|
|
defer bareRepo1.Close()
|
|
|
|
result, err := bareRepo1.IsCommitInBranch("2839944139e0de9737a044f78b0e4b40d989a9e3", "branch1")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, true, result)
|
|
|
|
result, err = bareRepo1.IsCommitInBranch("2839944139e0de9737a044f78b0e4b40d989a9e3", "branch2")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, false, result)
|
|
}
|