diff options
| author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-24 21:19:07 +0200 | 
|---|---|---|
| committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-24 21:19:07 +0200 | 
| commit | 402a6c2808db4333217aa300d0312836fd7923bd (patch) | |
| tree | 75936cb1c63dd34f7866c467ecd2ddb801425213 | |
| parent | feb1ea0f4aacb9ea6dc4133900e65bf34c0ee02d (diff) | |
| download | gitpython-402a6c2808db4333217aa300d0312836fd7923bd.tar.gz | |
IndexFile.add: writing of the index file can now optionally be turned off. The default is to write the physical index, which is the behaviour you would expect
| -rw-r--r-- | lib/git/index/base.py | 18 | ||||
| -rw-r--r-- | test/git/test_index.py | 3 | 
2 files changed, 14 insertions, 7 deletions
| diff --git a/lib/git/index/base.py b/lib/git/index/base.py index 7568b476..96cd6e40 100644 --- a/lib/git/index/base.py +++ b/lib/git/index/base.py @@ -581,10 +581,10 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):  		return (paths, entries)  	@git_working_dir -	def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=None): +	def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=None,  +				write=True):  		"""Add files from the working tree, specific blobs or BaseIndexEntries -		to the index. The underlying index file will be written immediately, hence -		you should provide as many items as possible to minimize the amounts of writes +		to the index.   		:param items:  			Multiple types of items are supported, types can be mixed within one call. @@ -653,6 +653,10 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):  			converted to Entries beforehand and passed to the path_rewriter.  			Please note that entry.path is relative to the git repository. +		:param write: +				If True, the index will be written once it was altered. Otherwise +				the changes only exist in memory and are not available to git commands. +		  		:return:  			List(BaseIndexEntries) representing the entries just actually added. @@ -748,11 +752,13 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):  		# END if there are base entries  		# FINALIZE -		# add the new entries to this instance, and write it +		# add the new entries to this instance  		for entry in entries_added:  			self.entries[(entry.path, 0)] = IndexEntry.from_base(entry) -		 -		self.write() +			 +		if write: +			self.write() +		# END handle write  		return entries_added diff --git a/test/git/test_index.py b/test/git/test_index.py index 929d40a3..09b49aaa 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -171,7 +171,8 @@ class TestIndex(TestBase):  		# pretend there was a change, but we do not even bother adding a proper   		# sha for it ( which makes things faster of course )  		manifest_fake_entry = BaseIndexEntry((manifest_entry[0], "\0"*20, 0, manifest_entry[3])) -		rw_repo.index.add([manifest_fake_entry]) +		# try write flag +		rw_repo.index.add([manifest_fake_entry], write=False)  		# add actually resolves the null-hex-sha for us as a feature, but we can   		# edit the index manually  		assert rw_repo.index.entries[manifest_key].binsha != Object.NULL_BIN_SHA | 
