@@ -84,3 +84,57 @@ func TestCherrypick(t *testing.T) {
84
84
t .Fatal ("Incorrect repository state: " , state )
85
85
}
86
86
}
87
+
88
+ func TestCherrypickCommit (t * testing.T ) {
89
+ t .Parallel ()
90
+ repo := createTestRepo (t )
91
+ defer cleanupTestRepo (t , repo )
92
+
93
+ c1 , _ := seedTestRepo (t , repo )
94
+ c2 , _ := updateReadme (t , repo , content )
95
+
96
+ commit1 , err := repo .LookupCommit (c1 )
97
+ if err != nil {
98
+ t .Fatal (err )
99
+ }
100
+ commit2 , err := repo .LookupCommit (c2 )
101
+ if err != nil {
102
+ t .Fatal (err )
103
+ }
104
+
105
+ checkout (t , repo , commit1 )
106
+
107
+ if got := readReadme (t , repo ); got == content {
108
+ t .Fatalf ("README = %q, want %q" , got , content )
109
+ }
110
+
111
+ opts , err := DefaultCherrypickOptions ()
112
+ if err != nil {
113
+ t .Fatal (err )
114
+ }
115
+
116
+ idx , err := repo .CherrypickCommit (commit2 , commit1 , opts )
117
+ if err != nil {
118
+ t .Fatal (err )
119
+ }
120
+ defer idx .Free ()
121
+
122
+ // The file is only updated in the index, not in the working directory.
123
+ if got := readReadme (t , repo ); got == content {
124
+ t .Errorf ("README = %q, want %q" , got , content )
125
+ }
126
+ if got := repo .State (); got != RepositoryStateNone {
127
+ t .Errorf ("repo.State() = %v, want %v" , got , RepositoryStateCherrypick )
128
+ }
129
+
130
+ if got := idx .EntryCount (); got != 1 {
131
+ t .Fatalf ("idx.EntryCount() = %v, want %v" , got , 1 )
132
+ }
133
+ entry , err := idx .EntryByIndex (0 )
134
+ if err != nil {
135
+ t .Fatal (err )
136
+ }
137
+ if entry .Path != "README" {
138
+ t .Errorf ("entry.Path = %v, want %v" , entry .Path , "README" )
139
+ }
140
+ }
0 commit comments