@@ -581,10 +581,10 @@ def _preprocess_add_items(self, items):
581581 return (paths , entries )
582582
583583 @git_working_dir
584- def add (self , items , force = True , fprogress = lambda * args : None , path_rewriter = None ):
584+ def add (self , items , force = True , fprogress = lambda * args : None , path_rewriter = None ,
585+ write = True ):
585586 """Add files from the working tree, specific blobs or BaseIndexEntries
586- to the index. The underlying index file will be written immediately, hence
587- you should provide as many items as possible to minimize the amounts of writes
587+ to the index.
588588
589589 :param items:
590590 Multiple types of items are supported, types can be mixed within one call.
@@ -653,6 +653,10 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
653653 converted to Entries beforehand and passed to the path_rewriter.
654654 Please note that entry.path is relative to the git repository.
655655
656+ :param write:
657+ If True, the index will be written once it was altered. Otherwise
658+ the changes only exist in memory and are not available to git commands.
659+
656660 :return:
657661 List(BaseIndexEntries) representing the entries just actually added.
658662
@@ -748,11 +752,13 @@ def store_path(filepath):
748752 # END if there are base entries
749753
750754 # FINALIZE
751- # add the new entries to this instance, and write it
755+ # add the new entries to this instance
752756 for entry in entries_added :
753757 self .entries [(entry .path , 0 )] = IndexEntry .from_base (entry )
754-
755- self .write ()
758+
759+ if write :
760+ self .write ()
761+ # END handle write
756762
757763 return entries_added
758764
0 commit comments