You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_compare_test.go 898B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import (
  6. "bytes"
  7. "io/ioutil"
  8. "os"
  9. "path/filepath"
  10. "testing"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestGetFormatPatch(t *testing.T) {
  14. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  15. clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestGetFormatPatch")
  16. assert.NoError(t, err)
  17. defer os.RemoveAll(clonedPath)
  18. repo, err := OpenRepository(clonedPath)
  19. assert.NoError(t, err)
  20. defer repo.Close()
  21. rd := &bytes.Buffer{}
  22. err = repo.GetPatch("8d92fc95^", "8d92fc95", rd)
  23. assert.NoError(t, err)
  24. patchb, err := ioutil.ReadAll(rd)
  25. assert.NoError(t, err)
  26. patch := string(patchb)
  27. assert.Regexp(t, "^From 8d92fc95", patch)
  28. assert.Contains(t, patch, "Subject: [PATCH] Add file2.txt")
  29. }