@@ -146,6 +146,22 @@ def from_blob(cls, blob):
146146 return IndexEntry ((time , time , 0 , 0 , blob .mode , 0 , 0 , blob .size , blob .id , 0 , blob .path ))
147147
148148
149+ def default_index (func ):
150+ """
151+ Decorator assuring the wrapped method may only run if we are the default
152+ repository index. This is as we rely on git commands that operate
153+ on that index only.
154+ """
155+ def check_default_index (self , * args , ** kwargs ):
156+ if self ._file_path != self ._index_path ():
157+ raise AssertionError ( "Cannot call %r on indices that do not represent the default git index" % func .__name__ )
158+ return func (self , * args , ** kwargs )
159+ # END wrpaper method
160+
161+ check_default_index .__name__ = func .__name__
162+ return check_default_index
163+
164+
149165class IndexFile (LazyMixin , diff .Diffable ):
150166 """
151167 Implements an Index that can be manipulated using a native implementation in
@@ -487,6 +503,22 @@ def resolve_blobs(self, iter_blobs):
487503 # END for each blob
488504
489505 return self
506+
507+ def update (self ):
508+ """
509+ Reread the contents of our index file, discarding all cached information
510+ we might have.
511+
512+ Note:
513+ This is a possibly dangerious operations as it will discard your changes
514+ to index.endtries
515+
516+ Returns
517+ self
518+ """
519+ del (self .entries )
520+ self .entries
521+ return self
490522
491523 def write_tree (self ):
492524 """
@@ -512,6 +544,88 @@ def _process_diff_args(self, args):
512544 # END remove self
513545 return args
514546
547+ @default_index
548+ def add (self , items , ** kwargs ):
549+ """
550+ Add files from the working copy, specific blobs or IndexEntries
551+ to the index.
552+
553+ TODO: Its important to specify a way to add symlinks directly, even
554+ on systems that do not support it, like ... erm ... windows.
555+
556+ ``**kwargs``
557+ Additional keyword arguments to be passed to git-update-index
558+
559+ Returns
560+ List(IndexEntries) representing the entries just added
561+ """
562+ raise NotImplementedError ("todo" )
563+
564+ @default_index
565+ def remove (self , items , affect_working_tree = False , ** kwargs ):
566+ """
567+ Remove the given file_paths or blobs from the index and optionally from
568+ the working tree as well.
569+
570+ ``items``
571+ TODO
572+
573+ ``affect_working_tree``
574+ If True, the entry will also be removed from the working tree, physically
575+ removing the respective file. This may fail if there are uncommited changes
576+ in it.
577+
578+ ``**kwargs``
579+ Additional keyword arguments to be passed to git-update-index
580+
581+ Returns
582+ self
583+ """
584+ raise NotImplementedError ("todo" )
585+ return self
586+
587+ @default_index
588+ def commit (self , message = None , parent_commits = None , ** kwargs ):
589+ """
590+ Commit the current index, creating a commit object.
591+
592+ ``message``
593+ Commit message
594+
595+ ``parent_commits``
596+ Optional Commit objects to use as parents for the new commit.
597+ If None or empty, the current head commit will be the parent of the
598+ new commit object
599+
600+ ``**kwargs``
601+ Additional keyword arguments passed to git-commit
602+
603+ Returns
604+ Commit object representing the new commit
605+ """
606+ raise NotImplementedError ("todo" )
607+
608+ @default_index
609+ def reset (self , commit = 'HEAD' , working_tree = False , ** kwargs ):
610+ """
611+ Reset the index to reflect the tree at the given commit. This will not
612+ adjust our HEAD reference as opposed to HEAD.reset.
613+
614+ ``commit``
615+ Revision, Reference or Commit specifying the commit we should represent.
616+ If you want to specify a tree only, use IndexFile.from_tree and overwrite
617+ the default index.
618+
619+ ``working_tree``
620+ If True, the files in the working tree will reflect the changed index.
621+ If False, the working tree will not be touched
622+
623+ ``**kwargs``
624+ Additional keyword arguments passed to git-reset
625+ """
626+ raise NotImplementedError ("todo" )
627+
628+ @default_index
515629 def diff (self , other = diff .Diffable .Index , paths = None , create_patch = False , ** kwargs ):
516630 """
517631 Diff this index against the working copy or a Tree or Commit object
@@ -523,10 +637,6 @@ def diff(self, other=diff.Diffable.Index, paths=None, create_patch=False, **kwar
523637 Will only work with indices that represent the default git index as
524638 they have not been initialized with a stream.
525639 """
526- # perhaps we shouldn't diff these at all, or we swap them in place first
527- if self ._file_path != self ._index_path ():
528- raise AssertionError ( "Cannot diff custom indices as they do not represent the default git index" )
529-
530640 # index against index is always empty
531641 if other is self .Index :
532642 return diff .DiffIndex ()
0 commit comments