From e9c29f82f24ded9adcba4c14acb17ada5e886127 Mon Sep 17 00:00:00 2001 From: truecode112 Date: Thu, 18 May 2023 11:47:12 +0300 Subject: [PATCH] doDeleteCommitAndPush implemented --- modules/git/commit.go | 8 +++++++ tests/integration/git_test.go | 44 +++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/modules/git/commit.go b/modules/git/commit.go index ff654f394d..b3db96a649 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -100,6 +100,14 @@ func AddChangesWithArgs(repoPath string, globalArgs TrustedCmdArgs, all bool, fi return err } +// DeleteChangesWithArgs marks local changes to be ready for commit. +func DeleteChangesWithArgs(repoPath string, globalArgs TrustedCmdArgs, files ...string) error { + cmd := NewCommandContextNoGlobals(DefaultContext, globalArgs...).AddArguments("rm") + cmd.AddDashesAndList(files...) + _, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath}) + return err +} + // CommitChangesOptions the options when a commit created type CommitChangesOptions struct { Committer *Signature diff --git a/tests/integration/git_test.go b/tests/integration/git_test.go index cdff57f21f..25f702ff14 100644 --- a/tests/integration/git_test.go +++ b/tests/integration/git_test.go @@ -102,14 +102,11 @@ func testGit(t *testing.T, u *url.URL) { }) t.Run("Deletion", func(t *testing.T) { defer tests.PrintCurrentTest(t)() - // TODO doDeleteCommitAndPush(t, littleSize, dstPath, "data-file-") + filename := doCommitAndPush(t, bigSize, dstForkedPath, "data-file-") + t.Run("APISetRepoSizeLimit", doAPISetRepoSizeLimit(forkedUserCtx, forkedUserCtx.Username, forkedUserCtx.Reponame, littleSize)) + err := doDeleteCommitAndPush(t, dstPath, filename) + assert.Error(t, err) }) - // TODO delete branch - // TODO delete tag - // TODO add big commit that will be over with the push - // TODO add lfs - // TODO remove lfs - // TODO add missing case }) t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &httpContext, "master", "test/head")) t.Run("BranchProtectMerge", doBranchProtectPRMerge(&httpContext, dstPath)) @@ -333,6 +330,15 @@ func doCommitAndPush(t *testing.T, size int, repoPath, prefix string) string { return name } +func doDeleteCommitAndPush(t *testing.T, repoPath, filename string) error { + var err = generateDeleteCommit(repoPath, "user2@example.com", "User Two", filename) + if err != nil { + return err + } + _, _, err = git.NewCommand(git.DefaultContext, "push", "origin", "master").RunStdString(&git.RunOpts{Dir: repoPath}) // Push + return err +} + func doCommitAndPushWithExpectedError(t *testing.T, size int, repoPath, prefix string) string { name, err := generateCommitWithNewData(size, repoPath, "user2@example.com", "User Two", prefix) assert.NoError(t, err) @@ -398,6 +404,30 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin return filepath.Base(tmpFile.Name()), err } +func generateDeleteCommit(repoPath, email, fullName, file string) error { + // Commit + // Now here we should explicitly allow lfs filters to run + globalArgs := git.AllowLFSFiltersArgs() + err := git.DeleteChangesWithArgs(repoPath, globalArgs, filepath.Base(file)) + if err != nil { + return err + } + err = git.CommitChangesWithArgs(repoPath, globalArgs, git.CommitChangesOptions{ + Committer: &git.Signature{ + Email: email, + Name: fullName, + When: time.Now(), + }, + Author: &git.Signature{ + Email: email, + Name: fullName, + When: time.Now(), + }, + Message: fmt.Sprintf("Testing commit @ %v", time.Now()), + }) + return err +} + func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { return func(t *testing.T) { defer tests.PrintCurrentTest(t)()