File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -278,6 +278,22 @@ func (v *Index) RemoveByPath(path string) error {
278
278
return nil
279
279
}
280
280
281
+ // RemoveDirectory removes all entries from the index under a given directory.
282
+ func (v * Index ) RemoveDirectory (dir string , stage int ) error {
283
+ cstr := C .CString (dir )
284
+ defer C .free (unsafe .Pointer (cstr ))
285
+
286
+ runtime .LockOSThread ()
287
+ defer runtime .UnlockOSThread ()
288
+
289
+ ret := C .git_index_remove_directory (v .ptr , cstr , C .int (stage ))
290
+ if ret < 0 {
291
+ return MakeGitError (ret )
292
+ }
293
+
294
+ return nil
295
+ }
296
+
281
297
func (v * Index ) WriteTreeTo (repo * Repository ) (* Oid , error ) {
282
298
oid := new (Oid )
283
299
Original file line number Diff line number Diff line change @@ -105,6 +105,46 @@ func TestIndexAddAndWriteTreeTo(t *testing.T) {
105
105
}
106
106
}
107
107
108
+ func TestIndexRemoveDirectory (t * testing.T ) {
109
+ repo := createTestRepo (t )
110
+ defer cleanupTestRepo (t , repo )
111
+
112
+ odb , err := repo .Odb ()
113
+ checkFatal (t , err )
114
+
115
+ blobID , err := odb .Write ([]byte ("fou\n " ), ObjectBlob )
116
+ checkFatal (t , err )
117
+
118
+ idx , err := NewIndex ()
119
+ checkFatal (t , err )
120
+
121
+ entryCount := idx .EntryCount ()
122
+ if entryCount != 0 {
123
+ t .Fatal ("Index should count 0 entry" )
124
+ }
125
+
126
+ entry := IndexEntry {
127
+ Path : "path/to/LISEZ_MOI" ,
128
+ Id : blobID ,
129
+ Mode : FilemodeBlob ,
130
+ }
131
+
132
+ err = idx .Add (& entry )
133
+ checkFatal (t , err )
134
+
135
+ entryCount = idx .EntryCount ()
136
+ if entryCount != 1 {
137
+ t .Fatal ("Index should count 1 entry" )
138
+ }
139
+
140
+ err = idx .RemoveDirectory ("path" , 0 )
141
+
142
+ entryCount = idx .EntryCount ()
143
+ if entryCount != 0 {
144
+ t .Fatal ("Index should count 0 entry" )
145
+ }
146
+ }
147
+
108
148
func TestIndexAddAllNoCallback (t * testing.T ) {
109
149
repo := createTestRepo (t )
110
150
defer cleanupTestRepo (t , repo )
You can’t perform that action at this time.
0 commit comments