Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHendrik 'T4cC0re' Meyer <code@t4cc0.re>2020-06-09 17:20:11 +0300
committerHendrik 'T4cC0re' Meyer <code@t4cc0.re>2020-06-09 17:31:28 +0300
commit8a1daafa720b790f14460ebd61d134a6df82412e (patch)
treea5408e912aac22d60c5397cf3d287b6f0bc1b050
parent5c49063cb05152e09e9fcf067b68b6de6a21d561 (diff)
Set a stable signature for .patch endpoints to create reproducible patches
This commit adds the `--signature` flag set to `GitLab` to the format-patch git subcommand used in RawPatch of the Diff service. This will result in the default signature of resulting .patch-files to be replaced with `GitLab`, resulting in more stable patches, that will not change file content based on the git version of the host (which is the default signature appended to the patch). This is relevant to be able to generate checksums or signatures for patches referenced via a GitLab URL. Implements #2842
-rw-r--r--changelogs/unreleased/t4cc0re-format-patch-no-sig.yml5
-rw-r--r--internal/service/diff/raw.go2
-rw-r--r--internal/service/diff/raw_test.go33
3 files changed, 39 insertions, 1 deletions
diff --git a/changelogs/unreleased/t4cc0re-format-patch-no-sig.yml b/changelogs/unreleased/t4cc0re-format-patch-no-sig.yml
new file mode 100644
index 000000000..1f0c7a663
--- /dev/null
+++ b/changelogs/unreleased/t4cc0re-format-patch-no-sig.yml
@@ -0,0 +1,5 @@
+---
+title: Set a stable signature for .patch endpoints to create reproducible patches
+merge_request: 2253
+author:
+type: changed
diff --git a/internal/service/diff/raw.go b/internal/service/diff/raw.go
index a65ac53cc..fb9540813 100644
--- a/internal/service/diff/raw.go
+++ b/internal/service/diff/raw.go
@@ -36,7 +36,7 @@ func (s *server) RawPatch(in *gitalypb.RawPatchRequest, stream gitalypb.DiffServ
subCmd := git.SubCmd{
Name: "format-patch",
- Flags: []git.Option{git.Flag{"--stdout"}},
+ Flags: []git.Option{git.Flag{"--stdout"}, git.ValueFlag{"--signature", "GitLab"}},
Args: []string{in.LeftCommitId + ".." + in.RightCommitId},
}
diff --git a/internal/service/diff/raw_test.go b/internal/service/diff/raw_test.go
index 4e3ce322a..02dbfc976 100644
--- a/internal/service/diff/raw_test.go
+++ b/internal/service/diff/raw_test.go
@@ -2,6 +2,8 @@ package diff
import (
"fmt"
+ "io/ioutil"
+ "regexp"
"testing"
"github.com/stretchr/testify/require"
@@ -202,6 +204,37 @@ func TestFailedRawPatchRequestDueToValidations(t *testing.T) {
}
}
+func TestRawPatchContainsGitLabSignature(t *testing.T) {
+ server, serverSocketPath := runDiffServer(t)
+ defer server.Stop()
+
+ client, conn := newDiffClient(t, serverSocketPath)
+ defer conn.Close()
+
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
+ defer cleanupFn()
+
+ rightCommit := "e395f646b1499e8e0279445fc99a0596a65fab7e"
+ leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
+ rpcRequest := &gitalypb.RawPatchRequest{Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
+
+ c, err := client.RawPatch(ctx, rpcRequest)
+ require.NoError(t, err)
+
+ reader := streamio.NewReader(func() ([]byte, error) {
+ response, err := c.Recv()
+ return response.GetData(), err
+ })
+
+ patch, err := ioutil.ReadAll(reader)
+ require.NoError(t, err)
+
+ require.Regexp(t, regexp.MustCompile(`\n-- \nGitLab\s+$`), string(patch))
+}
+
func drainRawDiffResponse(c gitalypb.DiffService_RawDiffClient) error {
var err error
for err == nil {