2013-06-29 12:46:33 +00:00
|
|
|
/*
|
|
|
|
* This file is part of gitg
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 - Jesse van den Kieboom
|
|
|
|
*
|
|
|
|
* gitg is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* gitg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with gitg. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-09-24 20:34:59 +00:00
|
|
|
using Gitg.Test;
|
2013-06-30 09:06:56 +00:00
|
|
|
using Gitg.Test.Assert;
|
|
|
|
|
2015-08-13 06:14:24 +00:00
|
|
|
class LibGitg.Test.Stage : Gitg.Test.Repository
|
2013-06-29 12:46:33 +00:00
|
|
|
{
|
2013-06-30 09:06:56 +00:00
|
|
|
/**
|
|
|
|
* Create basic repository with files in a variety of states.
|
|
|
|
*/
|
2013-06-29 12:46:33 +00:00
|
|
|
protected override void set_up()
|
|
|
|
{
|
|
|
|
base.set_up();
|
|
|
|
|
|
|
|
// Configure repository
|
|
|
|
commit("a", "hello world\n",
|
|
|
|
"b", "gitg test file\n",
|
|
|
|
"c", "hello\n");
|
|
|
|
|
|
|
|
workdir_remove("c");
|
|
|
|
workdir_modify("a", "changed world\n");
|
|
|
|
workdir_modify("b", "changed test\n");
|
|
|
|
|
|
|
|
index_modify("b", "staged changes\n");
|
|
|
|
}
|
|
|
|
|
2013-06-30 09:06:56 +00:00
|
|
|
private void check_file_status(MainLoop loop, Gee.HashMap<string, Ggit.StatusFlags> cfiles)
|
2013-06-29 12:46:33 +00:00
|
|
|
{
|
2013-06-30 09:06:56 +00:00
|
|
|
var seen = new Gee.HashSet<string>();
|
|
|
|
|
|
|
|
foreach (var f in cfiles.keys)
|
|
|
|
{
|
|
|
|
seen.add(f);
|
|
|
|
}
|
2013-06-29 18:00:12 +00:00
|
|
|
|
2013-07-03 15:14:10 +00:00
|
|
|
var stage = d_repository.stage;
|
2013-07-03 14:43:22 +00:00
|
|
|
var e = stage.file_status(null);
|
2013-06-29 12:46:33 +00:00
|
|
|
|
2014-12-13 14:41:40 +00:00
|
|
|
e.next_items.begin(-1, (obj, res) => {
|
|
|
|
var items = e.next_items.end(res);
|
2013-06-29 12:46:33 +00:00
|
|
|
|
2014-12-13 14:41:40 +00:00
|
|
|
assert(items.length == cfiles.size);
|
2013-06-29 18:00:12 +00:00
|
|
|
|
2014-12-13 14:41:40 +00:00
|
|
|
foreach (var item in items)
|
2013-06-29 12:46:33 +00:00
|
|
|
{
|
2014-12-13 14:41:40 +00:00
|
|
|
var f = item as Gitg.StageStatusFile;
|
|
|
|
|
2013-06-30 09:06:56 +00:00
|
|
|
assert(cfiles.has_key(f.path));
|
|
|
|
assert_inteq(cfiles[f.path], f.flags);
|
2013-06-29 12:46:33 +00:00
|
|
|
|
2013-06-30 09:06:56 +00:00
|
|
|
seen.remove(f.path);
|
|
|
|
}
|
2013-06-29 18:00:12 +00:00
|
|
|
|
2013-06-30 09:06:56 +00:00
|
|
|
assert(seen.size == 0);
|
2013-06-29 12:46:33 +00:00
|
|
|
loop.quit();
|
|
|
|
});
|
2013-06-30 09:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test whether the different file statuses created by the set_up()
|
|
|
|
* are properly reported by the stage file status enumerator.
|
|
|
|
*/
|
|
|
|
protected virtual signal void test_file_status()
|
|
|
|
{
|
|
|
|
var m = new Gee.HashMap<string, Ggit.StatusFlags>();
|
|
|
|
|
|
|
|
m["a"] = Ggit.StatusFlags.WORKING_TREE_MODIFIED;
|
|
|
|
m["b"] = Ggit.StatusFlags.WORKING_TREE_MODIFIED | Ggit.StatusFlags.INDEX_MODIFIED;
|
|
|
|
m["c"] = Ggit.StatusFlags.WORKING_TREE_DELETED;
|
|
|
|
|
|
|
|
var loop = new GLib.MainLoop();
|
|
|
|
|
|
|
|
check_file_status(loop, m);
|
|
|
|
loop.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test staging a complete file in the index.
|
|
|
|
*/
|
|
|
|
protected virtual signal void test_stage()
|
|
|
|
{
|
2013-07-03 15:14:10 +00:00
|
|
|
var stage = d_repository.stage;
|
2013-06-30 09:06:56 +00:00
|
|
|
|
|
|
|
var loop = new MainLoop();
|
|
|
|
|
2013-07-03 17:12:26 +00:00
|
|
|
stage.stage_path.begin("a", (obj, res) => {
|
2013-06-30 09:06:56 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
stage.stage.end(res);
|
2015-09-24 20:34:59 +00:00
|
|
|
} catch (Error e) { Assert.assert_no_error(e); }
|
2013-06-30 09:06:56 +00:00
|
|
|
|
|
|
|
var m = new Gee.HashMap<string, Ggit.StatusFlags>();
|
|
|
|
|
|
|
|
m["a"] = Ggit.StatusFlags.INDEX_MODIFIED;
|
|
|
|
m["b"] = Ggit.StatusFlags.WORKING_TREE_MODIFIED | Ggit.StatusFlags.INDEX_MODIFIED;
|
|
|
|
m["c"] = Ggit.StatusFlags.WORKING_TREE_DELETED;
|
|
|
|
|
|
|
|
check_file_status(loop, m);
|
|
|
|
});
|
|
|
|
|
|
|
|
loop.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test staging a complete file in the index.
|
|
|
|
*/
|
|
|
|
protected virtual signal void test_unstage()
|
|
|
|
{
|
2013-07-03 15:14:10 +00:00
|
|
|
var stage = d_repository.stage;
|
2013-06-30 09:06:56 +00:00
|
|
|
|
|
|
|
var loop = new MainLoop();
|
|
|
|
|
2013-07-03 17:12:26 +00:00
|
|
|
stage.unstage_path.begin("b", (obj, res) => {
|
2013-06-30 09:06:56 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
stage.unstage.end(res);
|
2015-09-24 20:34:59 +00:00
|
|
|
} catch (Error e) { Assert.assert_no_error(e); }
|
2013-06-30 09:06:56 +00:00
|
|
|
|
|
|
|
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 reverting a complete file in the index.
|
|
|
|
*/
|
|
|
|
protected virtual signal void test_revert()
|
|
|
|
{
|
2013-07-03 15:14:10 +00:00
|
|
|
var stage = d_repository.stage;
|
2013-06-30 09:06:56 +00:00
|
|
|
|
|
|
|
var loop = new MainLoop();
|
|
|
|
|
2013-07-03 17:12:26 +00:00
|
|
|
stage.revert_path.begin("a", (obj, res) => {
|
2013-06-30 09:06:56 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
stage.revert.end(res);
|
2015-09-24 20:34:59 +00:00
|
|
|
} catch (Error e) { Assert.assert_no_error(e); }
|
2013-06-30 09:06:56 +00:00
|
|
|
|
|
|
|
var m = new Gee.HashMap<string, Ggit.StatusFlags>();
|
|
|
|
|
|
|
|
m["b"] = Ggit.StatusFlags.INDEX_MODIFIED | 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()
|
|
|
|
{
|
2013-07-03 15:14:10 +00:00
|
|
|
var stage = d_repository.stage;
|
2013-06-30 09:06:56 +00:00
|
|
|
|
|
|
|
var loop = new MainLoop();
|
|
|
|
|
2013-07-03 17:12:26 +00:00
|
|
|
stage.delete_path.begin("c", (obj, res) => {
|
2013-06-30 09:06:56 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
stage.delete.end(res);
|
2015-09-24 20:34:59 +00:00
|
|
|
} catch (Error e) { Assert.assert_no_error(e); }
|
2013-06-30 09:06:56 +00:00
|
|
|
|
|
|
|
var m = new Gee.HashMap<string, Ggit.StatusFlags>();
|
|
|
|
|
|
|
|
m["a"] = Ggit.StatusFlags.WORKING_TREE_MODIFIED;
|
|
|
|
m["b"] = Ggit.StatusFlags.INDEX_MODIFIED | Ggit.StatusFlags.WORKING_TREE_MODIFIED;
|
|
|
|
m["c"] = Ggit.StatusFlags.INDEX_DELETED;
|
|
|
|
|
|
|
|
check_file_status(loop, m);
|
|
|
|
});
|
2013-06-29 12:46:33 +00:00
|
|
|
|
|
|
|
loop.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ex:set ts=4 noet
|