[gitg/wip/commit] Implemented reverting index



commit 28d6535c2f98d5d1fffed6d26741d01eda2a4117
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Wed Jul 3 19:12:26 2013 +0200

    Implemented reverting index

 libgitg/gitg-stage.vala       |   41 +++++++++++++++++++++++++++++++++++++++++
 libgitg/tests/test-stage.vala |   39 +++++++++++++++++++++++++++++++--------
 2 files changed, 72 insertions(+), 8 deletions(-)
---
diff --git a/libgitg/gitg-stage.vala b/libgitg/gitg-stage.vala
index 479ac9f..1331bf5 100644
--- a/libgitg/gitg-stage.vala
+++ b/libgitg/gitg-stage.vala
@@ -95,6 +95,47 @@ public class Stage : Object
        }
 
        /**
+        * Revert index changes.
+        *
+        * @param file the file to revert.
+        *
+        * Revert a file in the index to the version currently recorded in HEAD.
+        * Note that this only affects the index, not the working directory.
+        */
+       public async void revert_index(File file) throws Error
+       {
+               var tree = yield get_head_tree();
+
+               yield thread_index((index) => {
+                       // get path relative to the repository working directory
+                       var wd = d_repository.get_workdir();
+                       var path = wd.get_relative_path(file);
+
+                       // get the tree entry of that file
+                       var entry = tree.get_by_path(path);
+                       var id = entry.get_id();
+
+                       var ientry = d_repository.create_index_entry_for_file(file, id);
+                       index.add(ientry);
+
+                       index.write();
+               });
+       }
+
+       /**
+        * Revert index changes.
+        *
+        * @param path path relative to the working directory.
+        *
+        * Revert a path in the index to the version currently recorded in HEAD.
+        * Note that this only affects the index, not the working directory.
+        */
+       public async void revert_index_path(string path) throws Error
+       {
+               yield revert_index(d_repository.get_workdir().resolve_relative_path(path));
+       }
+
+       /**
         * Revert working directory changes.
         *
         * @param file the file to revert.
diff --git a/libgitg/tests/test-stage.vala b/libgitg/tests/test-stage.vala
index 7583ef5..ea1a20f 100644
--- a/libgitg/tests/test-stage.vala
+++ b/libgitg/tests/test-stage.vala
@@ -95,10 +95,9 @@ class Gitg.Test.Stage : Gitg.Test.Repository
        {
                var stage = d_repository.stage;
 
-               var f = d_repository.get_workdir().get_child("a");
                var loop = new MainLoop();
 
-               stage.stage.begin(f, (obj, res) => {
+               stage.stage_path.begin("a", (obj, res) => {
                        try
                        {
                                stage.stage.end(res);
@@ -123,10 +122,9 @@ class Gitg.Test.Stage : Gitg.Test.Repository
        {
                var stage = d_repository.stage;
 
-               var f = d_repository.get_workdir().get_child("b");
                var loop = new MainLoop();
 
-               stage.unstage.begin(f, (obj, res) => {
+               stage.unstage_path.begin("b", (obj, res) => {
                        try
                        {
                                stage.unstage.end(res);
@@ -151,10 +149,9 @@ class Gitg.Test.Stage : Gitg.Test.Repository
        {
                var stage = d_repository.stage;
 
-               var f = d_repository.get_workdir().get_child("a");
                var loop = new MainLoop();
 
-               stage.revert.begin(f, (obj, res) => {
+               stage.revert_path.begin("a", (obj, res) => {
                        try
                        {
                                stage.revert.end(res);
@@ -172,16 +169,42 @@ class Gitg.Test.Stage : Gitg.Test.Repository
        }
 
        /**
+        * test reverting a complete file from the index.
+        */
+       protected virtual signal void test_revert_index()
+       {
+               var stage = d_repository.stage;
+
+               var loop = new MainLoop();
+
+               stage.revert_index_path.begin("b", (obj, res) => {
+                       try
+                       {
+                               stage.revert_index.end(res);
+                       } catch (Error e) { assert_no_error(e); }
+
+                       var m = new Gee.HashMap<string, Ggit.StatusFlags>();
+
+                       m["a"] = Ggit.StatusFlags.WORKING_TREE_MODIFIED;
+                       m["b"] = Ggit.StatusFlags.WORKING_TREE_MODIFIED;
+                       m["c"] = Ggit.StatusFlags.WORKING_TREE_DELETED;
+
+                       check_file_status(loop, m);
+               });
+
+               loop.run();
+       }
+
+       /**
         * test deleting a file in the index.
         */
        protected virtual signal void test_delete()
        {
                var stage = d_repository.stage;
 
-               var f = d_repository.get_workdir().get_child("c");
                var loop = new MainLoop();
 
-               stage.delete.begin(f, (obj, res) => {
+               stage.delete_path.begin("c", (obj, res) => {
                        try
                        {
                                stage.delete.end(res);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]