github.com/purpleclay/gitz@v0.8.2-0.20240515052600-43f80eea2fe1/pull_test.go (about) 1 package git_test 2 3 import ( 4 "testing" 5 6 git "github.com/purpleclay/gitz" 7 "github.com/purpleclay/gitz/gittest" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestPull(t *testing.T) { 13 log := "(tag: 0.1.0, main, origin/main) feat: a new exciting feature" 14 gittest.InitRepository(t, gittest.WithRemoteLog(log)) 15 16 require.NotEqual(t, gittest.LastCommit(t).Message, "feat: a new exciting feature") 17 18 client, _ := git.NewClient() 19 _, err := client.Pull() 20 require.NoError(t, err) 21 22 assert.Equal(t, gittest.LastCommit(t).Message, "feat: a new exciting feature") 23 tags := gittest.Tags(t) 24 assert.ElementsMatch(t, []string{"0.1.0"}, tags) 25 } 26 27 func TestPullWithFetchIgnoreTags(t *testing.T) { 28 log := `(tag: 0.3.0, main, origin/main) feat: third feature 29 (tag: 0.2.0) feat: second feature 30 (tag: 0.1.0) feat: first feature` 31 gittest.InitRepository(t, gittest.WithRemoteLog(log)) 32 33 client, _ := git.NewClient() 34 _, err := client.Pull(git.WithFetchIgnoreTags()) 35 require.NoError(t, err) 36 37 assert.Empty(t, gittest.Tags(t)) 38 } 39 40 func TestPullWithPullRefSpecs(t *testing.T) { 41 log := `(main, origin/main) test: add test for validating refspecs 42 (origin/branch) fix: ensure pull supports refspecs` 43 gittest.InitRepository(t, gittest.WithLog(log)) 44 45 client, _ := git.NewClient() 46 _, err := client.Pull(git.WithPullRefSpecs("branch:branch1")) 47 48 require.NoError(t, err) 49 assert.ElementsMatch(t, []string{"main", "branch1"}, gittest.Branches(t)) 50 }