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_test.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package git
  4. import (
  5. "context"
  6. "path/filepath"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestGetLatestCommitTime(t *testing.T) {
  11. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  12. lct, err := GetLatestCommitTime(DefaultContext, bareRepo1Path)
  13. assert.NoError(t, err)
  14. // Time is Sun Nov 13 16:40:14 2022 +0100
  15. // which is the time of commit
  16. // ce064814f4a0d337b333e646ece456cd39fab612 (refs/heads/master)
  17. assert.EqualValues(t, 1668354014, lct.Unix())
  18. }
  19. func TestRepoIsEmpty(t *testing.T) {
  20. emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
  21. repo, err := openRepositoryWithDefaultContext(emptyRepo2Path)
  22. assert.NoError(t, err)
  23. defer repo.Close()
  24. isEmpty, err := repo.IsEmpty()
  25. assert.NoError(t, err)
  26. assert.True(t, isEmpty)
  27. }
  28. func TestRepoGetDivergingCommits(t *testing.T) {
  29. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  30. do, err := GetDivergingCommits(context.Background(), bareRepo1Path, "master", "branch2")
  31. assert.NoError(t, err)
  32. assert.Equal(t, DivergeObject{
  33. Ahead: 1,
  34. Behind: 5,
  35. }, do)
  36. do, err = GetDivergingCommits(context.Background(), bareRepo1Path, "master", "master")
  37. assert.NoError(t, err)
  38. assert.Equal(t, DivergeObject{
  39. Ahead: 0,
  40. Behind: 0,
  41. }, do)
  42. do, err = GetDivergingCommits(context.Background(), bareRepo1Path, "master", "test")
  43. assert.NoError(t, err)
  44. assert.Equal(t, DivergeObject{
  45. Ahead: 0,
  46. Behind: 2,
  47. }, do)
  48. }