mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-07-16 10:38:22 +00:00
Added diff-view test application
This commit is contained in:
parent
0be3e406b6
commit
0c51533d5b
|
@ -1,8 +1,19 @@
|
|||
INCLUDES = -g -I$(top_srcdir) -I$(top_srcdir)/gitg -I$(top_srcdir)/libgitg $(GITG_DEBUG_FLAGS) $(GITG_CFLAGS)
|
||||
|
||||
noinst_PROGRAMS = $(TEST_PROGS)
|
||||
progs_ldadd = $(top_builddir)/libgitg/libgitg-1.0.la $(PACKAGE_LIBS) $(GITG_LIBS)
|
||||
noinst_PROGRAMS = $(TEST_PROGS) $(DEMO_PROGS)
|
||||
|
||||
VALAFLAGS = $(GITG_PLUGIN_VALAFLAGS)
|
||||
|
||||
DEMO_PROGS = diff-view
|
||||
|
||||
diff_view_SOURCES = diff-view.vala
|
||||
diff_view_LDADD = $(GITG_PLUGIN_LIBS)
|
||||
diff_view_CFLAGS = $(GITG_PLUGIN_CFLAGS) -w
|
||||
|
||||
TESTS = $(TEST_PROGS)
|
||||
|
||||
BUILT_SOURCES = \
|
||||
diff_view_vala.stamp \
|
||||
$(diff_view_SOURCES:.vala=.c)
|
||||
|
||||
-include $(top_srcdir)/git.mk
|
||||
|
|
134
tests/diff-view.vala
Normal file
134
tests/diff-view.vala
Normal file
|
@ -0,0 +1,134 @@
|
|||
class TestDiffView
|
||||
{
|
||||
public static int main(string[] args)
|
||||
{
|
||||
Gtk.init(ref args);
|
||||
|
||||
if (Environment.get_variable("GITG_GTK_DIFF_VIEW_DEBUG") != "local" && args.length > 1 && args[1] == "--local")
|
||||
{
|
||||
// Launch in local mode
|
||||
var path = File.new_for_path(args[0]);
|
||||
var gtk = path.get_parent().get_parent().get_parent().get_child("libgitg-gtk");
|
||||
|
||||
var rargs = args;
|
||||
|
||||
rargs[0] = "../tests/diff-view";
|
||||
|
||||
for (var i = 1; i < rargs.length - 1; ++i)
|
||||
{
|
||||
rargs[i] = rargs[i + 2];
|
||||
}
|
||||
|
||||
int status;
|
||||
|
||||
var sliced = rargs[0:(rargs.length - 1)];
|
||||
|
||||
var env = Environ.get();
|
||||
env += "GITG_GTK_DIFF_VIEW_DEBUG=local";
|
||||
|
||||
try
|
||||
{
|
||||
Process.spawn_sync(gtk.get_path(),
|
||||
sliced,
|
||||
env,
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
out status);
|
||||
}
|
||||
catch (Error err)
|
||||
{
|
||||
stderr.printf("Error while spawning local version: %s\n", err.message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
var inipath = ".";
|
||||
|
||||
if (args.length > 1)
|
||||
{
|
||||
inipath = args[1];
|
||||
}
|
||||
|
||||
File repopath;
|
||||
Ggit.Repository repo;
|
||||
|
||||
try
|
||||
{
|
||||
repopath = Ggit.Repository.discover(File.new_for_commandline_arg(inipath));
|
||||
repo = Ggit.Repository.open(repopath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
stderr.printf("The specified path is not a git repository: %s\n", inipath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Ggit.Ref head;
|
||||
Ggit.Commit commit;
|
||||
|
||||
try
|
||||
{
|
||||
head = repo.get_head();
|
||||
commit = head.lookup() as Ggit.Commit;
|
||||
}
|
||||
catch
|
||||
{
|
||||
stderr.printf("The repository does not have a current HEAD\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var wnd = new Gtk.Window();
|
||||
wnd.set_default_size(800, 600);
|
||||
var sw = new Gtk.ScrolledWindow(null, null);
|
||||
|
||||
var v = new GitgGtk.DiffView(null);
|
||||
sw.add(v);
|
||||
|
||||
v.options = new Ggit.DiffOptions(Ggit.DiffFlags.NORMAL,
|
||||
3,
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
|
||||
v.commit = commit;
|
||||
|
||||
v.key_press_event.connect((vv, ev) => {
|
||||
var state = ev.state & Gtk.accelerator_get_default_mod_mask();
|
||||
|
||||
if (ev.keyval == Gdk.Key.r && state == Gdk.ModifierType.CONTROL_MASK)
|
||||
{
|
||||
v.reload_bypass_cache();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
wnd.delete_event.connect((w, ev) => {
|
||||
Gtk.main_quit();
|
||||
return true;
|
||||
});
|
||||
|
||||
wnd.add(sw);
|
||||
wnd.show_all();
|
||||
|
||||
if (Environment.get_variable("GITG_GTK_DIFF_VIEW_DEBUG") != "local")
|
||||
{
|
||||
stdout.printf("Use `diff-view --local' to use local resources.\n");
|
||||
}
|
||||
|
||||
stdout.printf("Press Ctrl+R to refresh...\n");
|
||||
|
||||
Gtk.main();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// vi:ts=4
|
Loading…
Reference in a new issue