diff options
author | 99rgosse <61579380+99rgosse@users.noreply.github.com> | 2021-12-23 09:32:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-23 16:32:29 +0800 |
commit | e0cf3d86c44fde99b49f12c7a1386cbf433a0207 (patch) | |
tree | b05b80758373312aa8c071b0a1317d5f03f6e7d7 /modules/git/repo_compare_test.go | |
parent | ba6efb105abd2a64b53491952a96a0a7af4b5ab9 (diff) | |
download | gitea-e0cf3d86c44fde99b49f12c7a1386cbf433a0207.tar.gz gitea-e0cf3d86c44fde99b49f12c7a1386cbf433a0207.zip |
Migrated Repository will show modifications when possible (#17191)
* Read patches to get history
Diffstat (limited to 'modules/git/repo_compare_test.go')
-rw-r--r-- | modules/git/repo_compare_test.go | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go index ecd1aa4e6d..4790170d10 100644 --- a/modules/git/repo_compare_test.go +++ b/modules/git/repo_compare_test.go @@ -8,6 +8,7 @@ import ( "bytes" "io" "path/filepath" + "strings" "testing" "code.gitea.io/gitea/modules/util" @@ -18,11 +19,11 @@ import ( 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) + repo, err := OpenRepository(clonedPath) defer repo.Close() + assert.NoError(t, err) rd := &bytes.Buffer{} err = repo.GetPatch("8d92fc95^", "8d92fc95", rd) assert.NoError(t, err) @@ -32,3 +33,49 @@ func TestGetFormatPatch(t *testing.T) { assert.Regexp(t, "^From 8d92fc95", patch) assert.Contains(t, patch, "Subject: [PATCH] Add file2.txt") } + +func TestReadPatch(t *testing.T) { + // Ensure we can read the patch files + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + repo, err := OpenRepository(bareRepo1Path) + defer repo.Close() + assert.NoError(t, err) + // This patch doesn't exist + noFile, err := repo.ReadPatchCommit(0) + assert.Error(t, err) + // This patch is an empty one (sometimes it's a 404) + noCommit, err := repo.ReadPatchCommit(1) + assert.Error(t, err) + // This patch is legit and should return a commit + oldCommit, err := repo.ReadPatchCommit(2) + assert.NoError(t, err) + + assert.Empty(t, noFile) + assert.Empty(t, noCommit) + assert.Len(t, oldCommit, 40) + assert.True(t, oldCommit == "6e8e2a6f9efd71dbe6917816343ed8415ad696c3") +} + +func TestReadWritePullHead(t *testing.T) { + // Ensure we can write SHA1 head corresponding to PR and open them + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + repo, err := OpenRepository(bareRepo1Path) + assert.NoError(t, err) + defer repo.Close() + // Try to open non-existing Pull + _, err = repo.ReadPullHead(0) + assert.Error(t, err) + // Write a fake sha1 with only 40 zeros + newCommit := strings.Repeat("0", 40) + err = repo.WritePullHead(1, newCommit) + assert.NoError(t, err) + headFile := filepath.Join(repo.Path, "refs/pull/1/head") + // Remove file after the test + defer util.Remove(headFile) + assert.FileExists(t, headFile) + // Read the file created + headContents, err := repo.ReadPullHead(1) + assert.NoError(t, err) + assert.Len(t, string(headContents), 40) + assert.True(t, string(headContents) == newCommit) +} |