@@ -28,14 +28,14 @@ const (
28
28
// RebaseOperation describes a single instruction/operation to be performed during the rebase.
29
29
type RebaseOperation struct {
30
30
Type RebaseOperationType
31
- ID * Oid
31
+ Id * Oid
32
32
Exec string
33
33
}
34
34
35
35
func newRebaseOperationFromC (c * C.git_rebase_operation ) * RebaseOperation {
36
36
operation := & RebaseOperation {}
37
37
operation .Type = RebaseOperationType (c ._type )
38
- operation .ID = newOidFromC (& c .id )
38
+ operation .Id = newOidFromC (& c .id )
39
39
operation .Exec = C .GoString (c .exec )
40
40
41
41
return operation
@@ -84,26 +84,26 @@ func (ro *RebaseOptions) toC() *C.git_rebase_options {
84
84
version : C .uint (ro .Version ),
85
85
quiet : C .int (ro .Quiet ),
86
86
inmemory : C .int (ro .InMemory ),
87
- rewrite_notes_ref : rewriteNotesRefToC (ro .RewriteNotesRef ),
87
+ rewrite_notes_ref : mapEmptyStringToNull (ro .RewriteNotesRef ),
88
88
merge_options : * ro .MergeOptions .toC (),
89
89
checkout_options : * ro .CheckoutOptions .toC (),
90
90
}
91
91
}
92
92
93
- func rewriteNotesRefToC (ref string ) * C.char {
93
+ func mapEmptyStringToNull (ref string ) * C.char {
94
94
if ref == "" {
95
95
return nil
96
96
}
97
97
return C .CString (ref )
98
98
}
99
99
100
- // Rebase object wrapper for C pointer
100
+ // Rebase is the struct representing a Rebase object.
101
101
type Rebase struct {
102
102
ptr * C.git_rebase
103
103
}
104
104
105
- //RebaseInit initializes a rebase operation to rebase the changes in branch relative to upstream onto another branch.
106
- func (r * Repository ) RebaseInit (branch * AnnotatedCommit , upstream * AnnotatedCommit , onto * AnnotatedCommit , opts * RebaseOptions ) (* Rebase , error ) {
105
+ // InitRebase initializes a rebase operation to rebase the changes in branch relative to upstream onto another branch.
106
+ func (r * Repository ) InitRebase (branch * AnnotatedCommit , upstream * AnnotatedCommit , onto * AnnotatedCommit , opts * RebaseOptions ) (* Rebase , error ) {
107
107
runtime .LockOSThread ()
108
108
defer runtime .UnlockOSThread ()
109
109
@@ -128,8 +128,8 @@ func (r *Repository) RebaseInit(branch *AnnotatedCommit, upstream *AnnotatedComm
128
128
return newRebaseFromC (ptr ), nil
129
129
}
130
130
131
- //RebaseOpen opens an existing rebase that was previously started by either an invocation of git_rebase_init or by another client.
132
- func (r * Repository ) RebaseOpen (opts * RebaseOptions ) (* Rebase , error ) {
131
+ // OpenRebase opens an existing rebase that was previously started by either an invocation of InitRebase or by another client.
132
+ func (r * Repository ) OpenRebase (opts * RebaseOptions ) (* Rebase , error ) {
133
133
runtime .LockOSThread ()
134
134
defer runtime .UnlockOSThread ()
135
135
@@ -149,9 +149,13 @@ func (rebase *Rebase) OperationAt(index uint) *RebaseOperation {
149
149
}
150
150
151
151
// CurrentOperationIndex gets the index of the rebase operation that is currently being applied.
152
- // If the first operation has not yet been applied then this returns -1 (C.GIT_REBASE_NO_OPERATION).
153
- func (rebase * Rebase ) CurrentOperationIndex () int {
154
- return int (C .git_rebase_operation_current (rebase .ptr ))
152
+ // Returns an error if no rebase operation is currently applied.
153
+ func (rebase * Rebase ) CurrentOperationIndex () (uint , error ) {
154
+ operationIndex := int (C .git_rebase_operation_current (rebase .ptr ))
155
+ if operationIndex == C .GIT_REBASE_NO_OPERATION {
156
+ return 0 , MakeGitError (C .GIT_REBASE_NO_OPERATION )
157
+ }
158
+ return uint (operationIndex ), nil
155
159
}
156
160
157
161
// OperationCount gets the count of rebase operations that are to be applied.
@@ -160,7 +164,7 @@ func (rebase *Rebase) OperationCount() uint {
160
164
}
161
165
162
166
// Next performs the next rebase operation and returns the information about it.
163
- // If the operation is one that applies a patch (which is any operation except GIT_REBASE_OPERATION_EXEC )
167
+ // If the operation is one that applies a patch (which is any operation except RebaseOperationExec )
164
168
// then the patch will be applied and the index and working directory will be updated with the changes.
165
169
// If there are conflicts, you will need to address those before committing the changes.
166
170
func (rebase * Rebase ) Next () (* RebaseOperation , error ) {
@@ -177,7 +181,7 @@ func (rebase *Rebase) Next() (*RebaseOperation, error) {
177
181
}
178
182
179
183
// Commit commits the current patch.
180
- // You must have resolved any conflicts that were introduced during the patch application from the git_rebase_next invocation.
184
+ // You must have resolved any conflicts that were introduced during the patch application from the Next() invocation.
181
185
func (rebase * Rebase ) Commit (ID * Oid , author , committer * Signature , message string ) error {
182
186
runtime .LockOSThread ()
183
187
defer runtime .UnlockOSThread ()
@@ -192,6 +196,7 @@ func (rebase *Rebase) Commit(ID *Oid, author, committer *Signature, message stri
192
196
if err != nil {
193
197
return err
194
198
}
199
+ defer C .git_signature_free (committerSig )
195
200
196
201
cmsg := C .CString (message )
197
202
defer C .free (unsafe .Pointer (cmsg ))
@@ -229,7 +234,7 @@ func (rebase *Rebase) Abort() error {
229
234
return nil
230
235
}
231
236
232
- //Free frees the Rebase object and underlying git_rebase C pointer .
237
+ // Free frees the Rebase object.
233
238
func (rebase * Rebase ) Free () {
234
239
runtime .SetFinalizer (rebase , nil )
235
240
C .git_rebase_free (rebase .ptr )
0 commit comments