@@ -198,6 +198,36 @@ public virtual void Add(string pathInTheWorkdir)
198
198
UpdatePhysicalIndex ( ) ;
199
199
}
200
200
201
+ /// <summary>
202
+ /// Adds an entry in the <see cref="Index"/> from a <see cref="Blob"/>.
203
+ /// <para>
204
+ /// If an entry with the same path already exists in the <see cref="Index"/>,
205
+ /// the newly added one will overwrite it.
206
+ /// </para>
207
+ /// </summary>
208
+ /// <param name="blob">The <see cref="Blob"/> which content should be added to the <see cref="Index"/>.</param>
209
+ /// <param name="indexEntryPath">The path to be used in the <see cref="Index"/>.</param>
210
+ /// <param name="indexEntryMode">Either <see cref="Mode.NonExecutableFile"/>, <see cref="Mode.ExecutableFile"/>
211
+ /// or <see cref="Mode.SymbolicLink"/>.</param>
212
+ public virtual void Add ( Blob blob , string indexEntryPath , Mode indexEntryMode )
213
+ {
214
+ Ensure . ArgumentConformsTo ( indexEntryMode , m => m . HasAny ( TreeEntryDefinition . BlobModes ) , "indexEntryMode" ) ;
215
+
216
+ if ( blob == null )
217
+ {
218
+ throw new ArgumentNullException ( "blob" ) ;
219
+ }
220
+
221
+ if ( indexEntryPath == null )
222
+ {
223
+ throw new ArgumentNullException ( "indexEntryPath" ) ;
224
+ }
225
+
226
+ AddEntryToTheIndex ( indexEntryPath , blob . Id , indexEntryMode ) ;
227
+
228
+ UpdatePhysicalIndex ( ) ;
229
+ }
230
+
201
231
private void UpdatePhysicalIndex ( )
202
232
{
203
233
Proxy . git_index_write ( handle ) ;
@@ -219,7 +249,11 @@ internal void Replace(TreeChanges changes)
219
249
case ChangeKind . Deleted :
220
250
/* Fall through */
221
251
case ChangeKind . Modified :
222
- ReplaceIndexEntryWith ( treeEntryChanges ) ;
252
+ AddEntryToTheIndex (
253
+ treeEntryChanges . OldPath ,
254
+ treeEntryChanges . OldOid ,
255
+ treeEntryChanges . OldMode ) ;
256
+
223
257
continue ;
224
258
225
259
default :
@@ -241,13 +275,13 @@ public virtual ConflictCollection Conflicts
241
275
}
242
276
}
243
277
244
- private void ReplaceIndexEntryWith ( TreeEntryChanges treeEntryChanges )
278
+ private void AddEntryToTheIndex ( string path , ObjectId id , Mode mode )
245
279
{
246
280
var indexEntry = new GitIndexEntry
247
281
{
248
- Mode = ( uint ) treeEntryChanges . OldMode ,
249
- Id = treeEntryChanges . OldOid . Oid ,
250
- Path = StrictFilePathMarshaler . FromManaged ( treeEntryChanges . OldPath ) ,
282
+ Mode = ( uint ) mode ,
283
+ Id = id . Oid ,
284
+ Path = StrictFilePathMarshaler . FromManaged ( path ) ,
251
285
} ;
252
286
253
287
Proxy . git_index_add ( handle , indexEntry ) ;
0 commit comments