Skip to content

Commit bf6e236

Browse files
committed
add a test
1 parent e5b8dcc commit bf6e236

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/integration/git_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package integration
55

66
import (
77
"bytes"
8+
"context"
89
"crypto/rand"
910
"encoding/hex"
1011
"fmt"
@@ -14,6 +15,7 @@ import (
1415
"path"
1516
"path/filepath"
1617
"strconv"
18+
"strings"
1719
"testing"
1820
"time"
1921

@@ -943,3 +945,54 @@ func TestDataAsync_Issue29101(t *testing.T) {
943945
defer r2.Close()
944946
})
945947
}
948+
949+
func TestAgitPullPush(t *testing.T) {
950+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
951+
baseAPITestContext := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
952+
953+
u.Path = baseAPITestContext.GitPath()
954+
u.User = url.UserPassword("user2", userPassword)
955+
956+
dstPath := t.TempDir()
957+
doGitClone(dstPath, u)(t)
958+
959+
gitRepo, err := git.OpenRepository(context.Background(), dstPath)
960+
assert.NoError(t, err)
961+
defer gitRepo.Close()
962+
963+
doGitCreateBranch(dstPath, "test-agit-push")
964+
965+
// commit 1
966+
_, err = generateCommitWithNewData(littleSize, dstPath, "[email protected]", "User Two", "branch-data-file-")
967+
assert.NoError(t, err)
968+
969+
// push to create an agit pull request
970+
err = git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master/test-agit-push").Run(&git.RunOpts{Dir: dstPath})
971+
assert.NoError(t, err)
972+
973+
// check pull request exist
974+
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: 1, Flow: issues_model.PullRequestFlowAGit, HeadBranch: "user2/test-agit-push"})
975+
976+
// commit 2
977+
_, err = generateCommitWithNewData(littleSize, dstPath, "[email protected]", "User Two", "branch-data-file-2-")
978+
assert.NoError(t, err)
979+
980+
// push 2
981+
err = git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master/test-agit-push").Run(&git.RunOpts{Dir: dstPath})
982+
assert.NoError(t, err)
983+
984+
// reset to first commit
985+
err = git.NewCommand(git.DefaultContext, "reset", "--hard", "HEAD~1").Run(&git.RunOpts{Dir: dstPath})
986+
assert.NoError(t, err)
987+
988+
// test force push without confirm
989+
stderr := strings.Builder{}
990+
err = git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master/test-agit-push").Run(&git.RunOpts{Dir: dstPath, Stderr: &stderr})
991+
assert.Error(t, err)
992+
assert.Contains(t, stderr.String(), "[remote rejected] HEAD -> refs/for/master/test-agit-push (request `force-push` push option)")
993+
994+
// test force push with confirm
995+
err = git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master/test-agit-push", "-o", "force-push").Run(&git.RunOpts{Dir: dstPath, Stderr: &stderr})
996+
assert.NoError(t, err)
997+
})
998+
}

0 commit comments

Comments
 (0)