Modify Index.write_tree() to have more robust Repository detection
Currently, Index.write_tree() relies on either the caller passing in a `repo=` arg or the underlying `git_index` being already bound to a `git_repository`. This ignores the case where the caller does not pass a `repo` argument to `Index.write_tree()` but the `Index._repo` property is populated on the index. This change modifies Index.write_tree() to use the passed-in `repo` argument, falls back to using `Index._repo` and then assumes that `git_index` must be bound to a `git_repository`. This change should make Index.write_tree() a little more robust in the most common use-case.
This commit is contained in:
		| @@ -157,6 +157,9 @@ class Index(object): | |||||||
|         It returns the id of the resulting tree. |         It returns the id of the resulting tree. | ||||||
|         """ |         """ | ||||||
|         coid = ffi.new('git_oid *') |         coid = ffi.new('git_oid *') | ||||||
|  |  | ||||||
|  |         repo = repo or self._repo | ||||||
|  |  | ||||||
|         if repo: |         if repo: | ||||||
|             err = C.git_index_write_tree_to(coid, self._index, repo._repo) |             err = C.git_index_write_tree_to(coid, self._index, repo._repo) | ||||||
|         else: |         else: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Mark Adams
					Mark Adams