summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGusted <postmaster@gusted.xyz>2024-02-23 21:42:15 +0100
committerGusted <postmaster@gusted.xyz>2024-02-23 21:42:15 +0100
commitf0ed6de89da27ec4d908a5a807fd5da4fbe62b7f (patch)
tree7bfaec9b25a7485f78ced9d148b6f5d3e0939230 /tests
parentMerge pull request 'Fixes & Improvements for English locale' (#2437) from 0ko... (diff)
downloadforgejo-f0ed6de89da27ec4d908a5a807fd5da4fbe62b7f.tar.xz
forgejo-f0ed6de89da27ec4d908a5a807fd5da4fbe62b7f.zip
[FEAT] Check if commit is already present in target branch
- Check if someone is (accidentally) trying to create a pull request via AGit with changes already in the target branch and fail if that is the case. - Added integration test.
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/git_test.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/tests/integration/git_test.go b/tests/integration/git_test.go
index d02427ffcf..125950a3a5 100644
--- a/tests/integration/git_test.go
+++ b/tests/integration/git_test.go
@@ -937,13 +937,13 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
})
})
+ upstreamGitRepo, err := git.OpenRepository(git.DefaultContext, filepath.Join(setting.RepoRootPath, ctx.Username, ctx.Reponame+".git"))
+ require.NoError(t, err)
+ defer upstreamGitRepo.Close()
+
t.Run("Force push", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
- upstreamGitRepo, err := git.OpenRepository(git.DefaultContext, filepath.Join(setting.RepoRootPath, ctx.Username, ctx.Reponame+".git"))
- require.NoError(t, err)
- defer upstreamGitRepo.Close()
-
_, _, gitErr := git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments("HEAD:refs/for/master/" + headBranch + "-force-push").RunStdString(&git.RunOpts{Dir: dstPath})
require.NoError(t, gitErr)
@@ -984,6 +984,21 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
})
})
+ t.Run("Branch already contains commit", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+
+ branchCommit, err := upstreamGitRepo.GetBranchCommit("master")
+ require.NoError(t, err)
+
+ _, _, gitErr := git.NewCommand(git.DefaultContext, "reset", "--hard").AddDynamicArguments(branchCommit.ID.String() + "~1").RunStdString(&git.RunOpts{Dir: dstPath})
+ require.NoError(t, gitErr)
+
+ _, stdErr, gitErr := git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments("HEAD:refs/for/master/" + headBranch + "-already-contains").RunStdString(&git.RunOpts{Dir: dstPath})
+ assert.Error(t, gitErr)
+
+ assert.Contains(t, stdErr, "already contains this commit")
+ })
+
t.Run("Merge", doAPIMergePullRequest(*ctx, ctx.Username, ctx.Reponame, pr1.Index))
t.Run("CheckoutMasterAgain", doGitCheckoutBranch(dstPath, "master"))
}