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 873B

12345678910111213141516171819202122232425262728293031
  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. "io/ioutil"
  7. "os"
  8. "path/filepath"
  9. "testing"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestGetFormatPatch(t *testing.T) {
  13. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  14. clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestGetFormatPatch")
  15. assert.NoError(t, err)
  16. defer os.RemoveAll(clonedPath)
  17. repo, err := OpenRepository(clonedPath)
  18. assert.NoError(t, err)
  19. defer repo.Close()
  20. rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95")
  21. assert.NoError(t, err)
  22. patchb, err := ioutil.ReadAll(rd)
  23. assert.NoError(t, err)
  24. patch := string(patchb)
  25. assert.Regexp(t, "^From 8d92fc95", patch)
  26. assert.Contains(t, patch, "Subject: [PATCH] Add file2.txt")
  27. }