diff options
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | lib/git/index.py | 118 | ||||
-rw-r--r-- | lib/git/refs.py | 3 | ||||
-rw-r--r-- | test/git/test_index.py | 13 |
4 files changed, 132 insertions, 5 deletions
@@ -58,6 +58,7 @@ Index is much slower. The thing is that properly writing a tree from an index involves creating several tree objects, so in the end it might be slower. Hmm, probably its okay to use the command unless we go c(++) +* Implement diff so that temporary indices can be used as well ( using file swapping ) * Proper merge handling with index and working copy * Checkout individual blobs using the index and git-checkout. Blobs can already be written using their stream_data method. @@ -74,6 +75,8 @@ Refs TagReference.create(repo, name * Ability to rename references and tags * Ability to remove references and tags +* Ability to checkout a reference - +* Check whether we are the active reference HEAD.commit == self.commit Remote ------ diff --git a/lib/git/index.py b/lib/git/index.py index 5452708d..9fd1fad2 100644 --- a/lib/git/index.py +++ b/lib/git/index.py @@ -146,6 +146,22 @@ class IndexEntry(tuple): return IndexEntry((time, time, 0, 0, blob.mode, 0, 0, blob.size, blob.id, 0, blob.path)) +def default_index(func): + """ + Decorator assuring the wrapped method may only run if we are the default + repository index. This is as we rely on git commands that operate + on that index only. + """ + def check_default_index(self, *args, **kwargs): + if self._file_path != self._index_path(): + raise AssertionError( "Cannot call %r on indices that do not represent the default git index" % func.__name__ ) + return func(self, *args, **kwargs) + # END wrpaper method + + check_default_index.__name__ = func.__name__ + return check_default_index + + class IndexFile(LazyMixin, diff.Diffable): """ Implements an Index that can be manipulated using a native implementation in @@ -487,6 +503,22 @@ class IndexFile(LazyMixin, diff.Diffable): # END for each blob return self + + def update(self): + """ + Reread the contents of our index file, discarding all cached information + we might have. + + Note: + This is a possibly dangerious operations as it will discard your changes + to index.endtries + + Returns + self + """ + del(self.entries) + self.entries + return self def write_tree(self): """ @@ -512,6 +544,88 @@ class IndexFile(LazyMixin, diff.Diffable): # END remove self return args + @default_index + def add(self, items, **kwargs): + """ + Add files from the working copy, specific blobs or IndexEntries + to the index. + + TODO: Its important to specify a way to add symlinks directly, even + on systems that do not support it, like ... erm ... windows. + + ``**kwargs`` + Additional keyword arguments to be passed to git-update-index + + Returns + List(IndexEntries) representing the entries just added + """ + raise NotImplementedError("todo") + + @default_index + def remove(self, items, affect_working_tree=False, **kwargs): + """ + Remove the given file_paths or blobs from the index and optionally from + the working tree as well. + + ``items`` + TODO + + ``affect_working_tree`` + If True, the entry will also be removed from the working tree, physically + removing the respective file. This may fail if there are uncommited changes + in it. + + ``**kwargs`` + Additional keyword arguments to be passed to git-update-index + + Returns + self + """ + raise NotImplementedError("todo") + return self + + @default_index + def commit(self, message=None, parent_commits=None, **kwargs): + """ + Commit the current index, creating a commit object. + + ``message`` + Commit message + + ``parent_commits`` + Optional Commit objects to use as parents for the new commit. + If None or empty, the current head commit will be the parent of the + new commit object + + ``**kwargs`` + Additional keyword arguments passed to git-commit + + Returns + Commit object representing the new commit + """ + raise NotImplementedError("todo") + + @default_index + def reset(self, commit='HEAD', working_tree=False, **kwargs): + """ + Reset the index to reflect the tree at the given commit. This will not + adjust our HEAD reference as opposed to HEAD.reset. + + ``commit`` + Revision, Reference or Commit specifying the commit we should represent. + If you want to specify a tree only, use IndexFile.from_tree and overwrite + the default index. + + ``working_tree`` + If True, the files in the working tree will reflect the changed index. + If False, the working tree will not be touched + + ``**kwargs`` + Additional keyword arguments passed to git-reset + """ + raise NotImplementedError("todo") + + @default_index def diff(self, other=diff.Diffable.Index, paths=None, create_patch=False, **kwargs): """ Diff this index against the working copy or a Tree or Commit object @@ -523,10 +637,6 @@ class IndexFile(LazyMixin, diff.Diffable): Will only work with indices that represent the default git index as they have not been initialized with a stream. """ - # perhaps we shouldn't diff these at all, or we swap them in place first - if self._file_path != self._index_path(): - raise AssertionError( "Cannot diff custom indices as they do not represent the default git index" ) - # index against index is always empty if other is self.Index: return diff.DiffIndex() diff --git a/lib/git/refs.py b/lib/git/refs.py index a83628ce..c8857e97 100644 --- a/lib/git/refs.py +++ b/lib/git/refs.py @@ -322,7 +322,8 @@ class HEAD(SymbolicReference): paths=None, **kwargs): """ Reset our HEAD to the given commit optionally synchronizing - the index and working tree. + the index and working tree. The reference we refer to will be set to + commit as well. ``commit`` Commit object, Reference Object or string identifying a revision we diff --git a/test/git/test_index.py b/test/git/test_index.py index 6fd3133a..36e57d5c 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -26,6 +26,11 @@ class TestTree(TestBase): val = getattr(entry, attr) # END for each method + # test update + entries = index.entries + assert isinstance(index.update(), IndexFile) + assert entries is not index.entries + # test stage index_merge = IndexFile(self.rorepo, fixture_path("index_merge")) assert len(index_merge.entries) == 106 @@ -140,3 +145,11 @@ class TestTree(TestBase): # against something unusual self.failUnlessRaises(ValueError, index.diff, int) + + self.fail( "Test IndexFile.reset" ) + + @with_rw_repo('0.1.6') + def test_index_mutation(self, rw_repo): + # add / remove / commit / Working Tree Handling + self.fail( "add, remove, commit, working tree handling" ) + |