aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/repo_compare_test.go
blob: ecd1aa4e6da04c7d5a19a78136fd86823b823830 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 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 (
	"bytes"
	"io"
	"path/filepath"
	"testing"

	"code.gitea.io/gitea/modules/util"

	"github.com/stretchr/testify/assert"
)

func TestGetFormatPatch(t *testing.T) {
	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
	clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestGetFormatPatch")
	assert.NoError(t, err)
	defer util.RemoveAll(clonedPath)
	repo, err := OpenRepository(clonedPath)
	assert.NoError(t, err)
	defer repo.Close()
	rd := &bytes.Buffer{}
	err = repo.GetPatch("8d92fc95^", "8d92fc95", rd)
	assert.NoError(t, err)
	patchb, err := io.ReadAll(rd)
	assert.NoError(t, err)
	patch := string(patchb)
	assert.Regexp(t, "^From 8d92fc95", patch)
	assert.Contains(t, patch, "Subject: [PATCH] Add file2.txt")
}