@@ -198,6 +198,36 @@ public virtual void Add(string pathInTheWorkdir)
198198 UpdatePhysicalIndex ( ) ;
199199 }
200200
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+
201231 private void UpdatePhysicalIndex ( )
202232 {
203233 Proxy . git_index_write ( handle ) ;
@@ -219,7 +249,11 @@ internal void Replace(TreeChanges changes)
219249 case ChangeKind . Deleted :
220250 /* Fall through */
221251 case ChangeKind . Modified :
222- ReplaceIndexEntryWith ( treeEntryChanges ) ;
252+ AddEntryToTheIndex (
253+ treeEntryChanges . OldPath ,
254+ treeEntryChanges . OldOid ,
255+ treeEntryChanges . OldMode ) ;
256+
223257 continue ;
224258
225259 default :
@@ -241,13 +275,13 @@ public virtual ConflictCollection Conflicts
241275 }
242276 }
243277
244- private void ReplaceIndexEntryWith ( TreeEntryChanges treeEntryChanges )
278+ private void AddEntryToTheIndex ( string path , ObjectId id , Mode mode )
245279 {
246280 var indexEntry = new GitIndexEntry
247281 {
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 ) ,
251285 } ;
252286
253287 Proxy . git_index_add ( handle , indexEntry ) ;
0 commit comments