@@ -711,7 +711,7 @@ def remove(self, items, working_tree=False, **kwargs):
711711 return [ p [4 :- 1 ] for p in removed_paths ]
712712
713713 @default_index
714- def commit (self , message , parent_commits = None ):
714+ def commit (self , message , parent_commits = None , head = True ):
715715 """
716716 Commit the current index, creating a commit object.
717717
@@ -726,6 +726,11 @@ def commit(self, message, parent_commits=None):
726726 If None , the current head commit will be the parent of the
727727 new commit object
728728
729+ ``head``
730+ If True, the HEAD will be advanced to the new commit automatically.
731+ Else the HEAD will remain pointing on the previous commit. This could
732+ lead to undesired results when diffing files.
733+
729734 Returns
730735 Commit object representing the new commit
731736
@@ -752,17 +757,23 @@ def commit(self, message, parent_commits=None):
752757 # write the current index as tree
753758 tree_sha = self .repo .git .write_tree ()
754759 commit_sha = self .repo .git .commit_tree (tree_sha , parent_args , istream = fp )
755- return Commit (self .repo , commit_sha )
760+ new_commit = Commit (self .repo , commit_sha )
761+
762+ if head :
763+ self .repo .head .commit = new_commit
764+ # END advance head handling
765+
766+ return new_commit
756767 finally :
757768 fp .close ()
758769 os .remove (tmp_file_path )
759-
770+
760771 @clear_cache
761772 @default_index
762- def reset (self , commit = 'HEAD' , working_tree = False , paths = None , ** kwargs ):
773+ def reset (self , commit = 'HEAD' , working_tree = False , paths = None , head = False , ** kwargs ):
763774 """
764775 Reset the index to reflect the tree at the given commit. This will not
765- adjust our HEAD reference as opposed to HEAD.reset.
776+ adjust our HEAD reference as opposed to HEAD.reset by default .
766777
767778 ``commit``
768779 Revision, Reference or Commit specifying the commit we should represent.
@@ -775,19 +786,27 @@ def reset(self, commit='HEAD', working_tree=False, paths=None, **kwargs):
775786 Please note that changes to the working copy will be discarded without
776787 warning !
777788
789+ ``head``
790+ If True, the head will be set to the given commit. This is False by default,
791+ but if True, this method behaves like HEAD.reset.
792+
778793 ``**kwargs``
779794 Additional keyword arguments passed to git-reset
780795
781796 Returns
782797 self
783798 """
784- head = self .repo .head
785- prev_commit = head .commit
799+ cur_head = self .repo .head
800+ prev_commit = cur_head .commit
786801
787802 # reset to get the tree/working copy
788- head .reset (commit , index = True , working_tree = working_tree , paths = paths , ** kwargs )
789- # put the head back
790- head .reset (prev_commit , index = False , working_tree = False )
803+ cur_head .reset (commit , index = True , working_tree = working_tree , paths = paths , ** kwargs )
804+
805+ # put the head back, possibly
806+ if not head :
807+ cur_head .reset (prev_commit , index = False , working_tree = False )
808+ # END reset head
809+
791810 return self
792811
793812 @default_index
0 commit comments