mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-08-24 18:36:25 +00:00
Added pre-commit and post-commit hook execution
This commit is contained in:
parent
d66f89c96c
commit
c5b60b9e7f
|
@ -378,22 +378,24 @@ static gchar *
|
||||||
get_stash_refspec (GitgRepository *repository, GitgRef *stash)
|
get_stash_refspec (GitgRepository *repository, GitgRef *stash)
|
||||||
{
|
{
|
||||||
gchar **out;
|
gchar **out;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
out = gitg_shell_run_sync_with_output (gitg_command_new (repository,
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (repository,
|
||||||
"log",
|
"log",
|
||||||
"--no-color",
|
"--no-color",
|
||||||
"--pretty=oneline",
|
"--pretty=oneline",
|
||||||
"-g",
|
"-g",
|
||||||
"refs/stash",
|
"refs/stash",
|
||||||
NULL),
|
NULL),
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
&out,
|
||||||
|
NULL);
|
||||||
|
|
||||||
gchar **ptr = out;
|
gchar **ptr = out;
|
||||||
gchar *sha1 = gitg_hash_hash_to_sha1_new (gitg_ref_get_hash (stash));
|
gchar *sha1 = gitg_hash_hash_to_sha1_new (gitg_ref_get_hash (stash));
|
||||||
gchar *ret = NULL;
|
gchar *ret = NULL;
|
||||||
|
|
||||||
while (ptr && *ptr)
|
while (retval && ptr && *ptr)
|
||||||
{
|
{
|
||||||
if (g_str_has_prefix (*ptr, sha1))
|
if (g_str_has_prefix (*ptr, sha1))
|
||||||
{
|
{
|
||||||
|
|
|
@ -2587,7 +2587,17 @@ on_commit_clicked (GtkButton *button,
|
||||||
show_error (view, _("Your user name or email could not be retrieved for use in the sign off message"));
|
show_error (view, _("Your user name or email could not be retrieved for use in the sign off message"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
show_error (view, _("Something went wrong while trying to commit"));
|
{
|
||||||
|
gchar *msg;
|
||||||
|
|
||||||
|
msg = g_strconcat (_("Something went wrong while trying to commit"),
|
||||||
|
":\n\n",
|
||||||
|
error->message,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
show_error (view, msg);
|
||||||
|
g_free (msg);
|
||||||
|
}
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
|
|
|
@ -776,14 +776,15 @@ revision_to_text (GitgRepository *repository,
|
||||||
gchar **lines;
|
gchar **lines;
|
||||||
gchar *sha1 = gitg_revision_get_sha1 (revision);
|
gchar *sha1 = gitg_revision_get_sha1 (revision);
|
||||||
|
|
||||||
lines = gitg_shell_run_sync_with_output (gitg_command_new (repository,
|
gitg_shell_run_sync_with_output (gitg_command_new (repository,
|
||||||
"log",
|
"log",
|
||||||
"-1",
|
"-1",
|
||||||
"--pretty=format:%h: %s%n%n%b",
|
"--pretty=format:%h: %s%n%n%b",
|
||||||
sha1,
|
sha1,
|
||||||
NULL),
|
NULL),
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
&lines,
|
||||||
|
NULL);
|
||||||
|
|
||||||
remove_trailing_newlines (lines);
|
remove_trailing_newlines (lines);
|
||||||
gchar *ret = g_strjoinv ("\n", lines);
|
gchar *ret = g_strjoinv ("\n", lines);
|
||||||
|
|
|
@ -587,8 +587,10 @@ update_index_staged (GitgCommit *commit,
|
||||||
GFile *f = gitg_changed_file_get_file (file);
|
GFile *f = gitg_changed_file_get_file (file);
|
||||||
gchar *path = gitg_repository_relative (commit->priv->repository, f);
|
gchar *path = gitg_repository_relative (commit->priv->repository, f);
|
||||||
gchar *head = gitg_repository_parse_head (commit->priv->repository);
|
gchar *head = gitg_repository_parse_head (commit->priv->repository);
|
||||||
|
gboolean retval;
|
||||||
|
gchar **ret;
|
||||||
|
|
||||||
gchar **ret = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
||||||
"diff-index",
|
"diff-index",
|
||||||
"--no-ext-diff",
|
"--no-ext-diff",
|
||||||
"--cached",
|
"--cached",
|
||||||
|
@ -597,14 +599,16 @@ update_index_staged (GitgCommit *commit,
|
||||||
path,
|
path,
|
||||||
NULL),
|
NULL),
|
||||||
FALSE,
|
FALSE,
|
||||||
|
&ret,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
g_free (path);
|
g_free (path);
|
||||||
g_free (head);
|
g_free (head);
|
||||||
g_object_unref (f);
|
g_object_unref (f);
|
||||||
|
|
||||||
if (!ret)
|
if (!retval)
|
||||||
{
|
{
|
||||||
|
g_strfreev (ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,21 +645,23 @@ update_index_unstaged (GitgCommit *commit,
|
||||||
{
|
{
|
||||||
GFile *f = gitg_changed_file_get_file (file);
|
GFile *f = gitg_changed_file_get_file (file);
|
||||||
gchar *path = gitg_repository_relative (commit->priv->repository, f);
|
gchar *path = gitg_repository_relative (commit->priv->repository, f);
|
||||||
|
gboolean retval;
|
||||||
gchar **ret;
|
gchar **ret;
|
||||||
|
|
||||||
ret = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
||||||
"diff-files",
|
"diff-files",
|
||||||
"--no-ext-diff",
|
"--no-ext-diff",
|
||||||
"--",
|
"--",
|
||||||
path,
|
path,
|
||||||
NULL),
|
NULL),
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
&ret,
|
||||||
|
NULL);
|
||||||
|
|
||||||
g_free (path);
|
g_free (path);
|
||||||
g_object_unref (f);
|
g_object_unref (f);
|
||||||
|
|
||||||
if (ret && *ret)
|
if (retval && ret && *ret)
|
||||||
{
|
{
|
||||||
gitg_changed_file_set_changes (file,
|
gitg_changed_file_set_changes (file,
|
||||||
gitg_changed_file_get_changes (file) |
|
gitg_changed_file_get_changes (file) |
|
||||||
|
@ -668,10 +674,7 @@ update_index_unstaged (GitgCommit *commit,
|
||||||
~GITG_CHANGED_FILE_CHANGES_UNSTAGED);
|
~GITG_CHANGED_FILE_CHANGES_UNSTAGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret)
|
g_strfreev (ret);
|
||||||
{
|
|
||||||
g_strfreev (ret);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -885,13 +888,17 @@ comment_parse_subject (gchar const *comment)
|
||||||
static gboolean
|
static gboolean
|
||||||
write_tree (GitgCommit *commit, gchar **tree, GError **error)
|
write_tree (GitgCommit *commit, gchar **tree, GError **error)
|
||||||
{
|
{
|
||||||
gchar **lines = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
gchar **lines;
|
||||||
"write-tree",
|
gboolean retval;
|
||||||
NULL),
|
|
||||||
FALSE,
|
|
||||||
error);
|
|
||||||
|
|
||||||
if (!lines || strlen (*lines) != GITG_HASH_SHA_SIZE)
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
||||||
|
"write-tree",
|
||||||
|
NULL),
|
||||||
|
FALSE,
|
||||||
|
&lines,
|
||||||
|
error);
|
||||||
|
|
||||||
|
if (!retval || !lines || strlen (*lines) != GITG_HASH_SHA_SIZE)
|
||||||
{
|
{
|
||||||
g_strfreev (lines);
|
g_strfreev (lines);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -906,15 +913,20 @@ write_tree (GitgCommit *commit, gchar **tree, GError **error)
|
||||||
static gchar *
|
static gchar *
|
||||||
get_signed_off_line (GitgCommit *commit)
|
get_signed_off_line (GitgCommit *commit)
|
||||||
{
|
{
|
||||||
gchar **user = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
gchar **user;
|
||||||
"config",
|
gboolean retval;
|
||||||
"--get",
|
gchar **email;
|
||||||
"user.name",
|
|
||||||
NULL),
|
|
||||||
FALSE,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (!user)
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
||||||
|
"config",
|
||||||
|
"--get",
|
||||||
|
"user.name",
|
||||||
|
NULL),
|
||||||
|
FALSE,
|
||||||
|
&user,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (!retval || !user)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -925,15 +937,16 @@ get_signed_off_line (GitgCommit *commit)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar **email = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
||||||
"config",
|
"config",
|
||||||
"--get",
|
"--get",
|
||||||
"user.email",
|
"user.email",
|
||||||
NULL),
|
NULL),
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
&email,
|
||||||
|
NULL);
|
||||||
|
|
||||||
if (!email)
|
if (!retval || !email)
|
||||||
{
|
{
|
||||||
g_strfreev (user);
|
g_strfreev (user);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -959,14 +972,22 @@ set_amend_environment (GitgCommit *commit,
|
||||||
GitgCommand *command)
|
GitgCommand *command)
|
||||||
{
|
{
|
||||||
gchar **out;
|
gchar **out;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
out = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
||||||
"cat-file",
|
"cat-file",
|
||||||
"commit",
|
"commit",
|
||||||
"HEAD",
|
"HEAD",
|
||||||
NULL),
|
NULL),
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
&out,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (!retval)
|
||||||
|
{
|
||||||
|
g_strfreev (out);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse author
|
// Parse author
|
||||||
GRegex *r = g_regex_new ("^author (.*) < ([^>]*)> ([0-9]+.*)$",
|
GRegex *r = g_regex_new ("^author (.*) < ([^>]*)> ([0-9]+.*)$",
|
||||||
|
@ -1054,6 +1075,7 @@ commit_tree (GitgCommit *commit,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gchar *fullcomment;
|
gchar *fullcomment;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
if (signoff)
|
if (signoff)
|
||||||
{
|
{
|
||||||
|
@ -1109,9 +1131,10 @@ commit_tree (GitgCommit *commit,
|
||||||
|
|
||||||
gchar *converted = convert_commit_encoding (commit, fullcomment);
|
gchar *converted = convert_commit_encoding (commit, fullcomment);
|
||||||
|
|
||||||
buffer = gitg_shell_run_sync_with_input_and_output (command,
|
retval = gitg_shell_run_sync_with_input_and_output (command,
|
||||||
FALSE,
|
FALSE,
|
||||||
converted,
|
converted,
|
||||||
|
&buffer,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
g_free (head);
|
g_free (head);
|
||||||
|
@ -1119,7 +1142,7 @@ commit_tree (GitgCommit *commit,
|
||||||
g_free (converted);
|
g_free (converted);
|
||||||
g_object_unref (command);
|
g_object_unref (command);
|
||||||
|
|
||||||
if (!buffer || !*buffer || strlen (*buffer) != GITG_HASH_SHA_SIZE)
|
if (!retval || !buffer || !*buffer || strlen (*buffer) != GITG_HASH_SHA_SIZE)
|
||||||
{
|
{
|
||||||
g_strfreev (buffer);
|
g_strfreev (buffer);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -1163,6 +1186,14 @@ gitg_commit_commit (GitgCommit *commit,
|
||||||
|
|
||||||
gchar *tree;
|
gchar *tree;
|
||||||
|
|
||||||
|
if (!gitg_repository_run_hook (commit->priv->repository,
|
||||||
|
"pre-commit",
|
||||||
|
error,
|
||||||
|
NULL))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!write_tree (commit, &tree, error))
|
if (!write_tree (commit, &tree, error))
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -1196,6 +1227,11 @@ gitg_commit_commit (GitgCommit *commit,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gitg_repository_run_hook (commit->priv->repository,
|
||||||
|
"post-commit",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
gitg_repository_reload (commit->priv->repository);
|
gitg_repository_reload (commit->priv->repository);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -1366,21 +1402,23 @@ gitg_commit_find_changed_file (GitgCommit *commit,
|
||||||
gchar *
|
gchar *
|
||||||
gitg_commit_amend_message (GitgCommit *commit)
|
gitg_commit_amend_message (GitgCommit *commit)
|
||||||
{
|
{
|
||||||
|
gchar **out;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
g_return_val_if_fail (GITG_IS_COMMIT (commit), NULL);
|
g_return_val_if_fail (GITG_IS_COMMIT (commit), NULL);
|
||||||
|
|
||||||
gchar **out;
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
||||||
|
"cat-file",
|
||||||
out = gitg_shell_run_sync_with_output (gitg_command_new (commit->priv->repository,
|
"commit",
|
||||||
"cat-file",
|
"HEAD",
|
||||||
"commit",
|
NULL),
|
||||||
"HEAD",
|
FALSE,
|
||||||
NULL),
|
&out,
|
||||||
FALSE,
|
NULL);
|
||||||
NULL);
|
|
||||||
|
|
||||||
gchar *ret = NULL;
|
gchar *ret = NULL;
|
||||||
|
|
||||||
if (out)
|
if (retval && out)
|
||||||
{
|
{
|
||||||
gchar **ptr = out;
|
gchar **ptr = out;
|
||||||
|
|
||||||
|
|
|
@ -611,17 +611,22 @@ parse_ref_intern (GitgRepository *repository,
|
||||||
gchar const *ref,
|
gchar const *ref,
|
||||||
gboolean symbolic)
|
gboolean symbolic)
|
||||||
{
|
{
|
||||||
gchar **ret = gitg_shell_run_sync_with_output (gitg_command_new (repository,
|
gchar **ret;
|
||||||
"rev-parse",
|
gboolean retval;
|
||||||
"--verify",
|
|
||||||
symbolic ? "--symbolic-full-name" : ref,
|
|
||||||
symbolic ? ref : NULL,
|
|
||||||
NULL),
|
|
||||||
FALSE,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (!ret)
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (repository,
|
||||||
|
"rev-parse",
|
||||||
|
"--verify",
|
||||||
|
symbolic ? "--symbolic-full-name" : ref,
|
||||||
|
symbolic ? ref : NULL,
|
||||||
|
NULL),
|
||||||
|
FALSE,
|
||||||
|
&ret,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (!retval || !ret)
|
||||||
{
|
{
|
||||||
|
g_strfreev (ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1407,6 +1412,7 @@ load_current_ref (GitgRepository *self)
|
||||||
gchar *ret = NULL;
|
gchar *ret = NULL;
|
||||||
gint i;
|
gint i;
|
||||||
gint numargs;
|
gint numargs;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
if (self->priv->last_args == NULL)
|
if (self->priv->last_args == NULL)
|
||||||
{
|
{
|
||||||
|
@ -1426,12 +1432,14 @@ load_current_ref (GitgRepository *self)
|
||||||
argv[2 + i] = self->priv->last_args[i];
|
argv[2 + i] = self->priv->last_args[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
out = gitg_shell_run_sync_with_output (gitg_command_newv (self, argv),
|
retval = gitg_shell_run_sync_with_output (gitg_command_newv (self, argv),
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
&out,
|
||||||
|
NULL);
|
||||||
|
|
||||||
if (!out)
|
if (!retval || !out)
|
||||||
{
|
{
|
||||||
|
g_strfreev (out);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1448,17 +1456,20 @@ static void
|
||||||
load_refs (GitgRepository *self)
|
load_refs (GitgRepository *self)
|
||||||
{
|
{
|
||||||
gchar **refs;
|
gchar **refs;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
refs = gitg_shell_run_sync_with_output (gitg_command_new (self,
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (self,
|
||||||
"for-each-ref",
|
"for-each-ref",
|
||||||
"--format=%(refname) %(objectname) %(*objectname)",
|
"--format=%(refname) %(objectname) %(*objectname)",
|
||||||
"refs",
|
"refs",
|
||||||
NULL),
|
NULL),
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
&refs,
|
||||||
|
NULL);
|
||||||
|
|
||||||
if (!refs)
|
if (!retval || !refs)
|
||||||
{
|
{
|
||||||
|
g_strfreev (refs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1914,3 +1925,117 @@ gitg_repository_exists (GitgRepository *repository)
|
||||||
return g_file_query_exists (repository->priv->git_dir, NULL) &&
|
return g_file_query_exists (repository->priv->git_dir, NULL) &&
|
||||||
g_file_query_exists (repository->priv->work_tree, NULL);
|
g_file_query_exists (repository->priv->work_tree, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gitg_repository_run_hook (GitgRepository *repository,
|
||||||
|
gchar const *name,
|
||||||
|
GError **error,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
GFile *hooksdir;
|
||||||
|
GFile *hookfile;
|
||||||
|
GitgCommand *command;
|
||||||
|
gchar *path;
|
||||||
|
GPtrArray *args;
|
||||||
|
gchar **argsv;
|
||||||
|
gchar **ret;
|
||||||
|
va_list ap;
|
||||||
|
gchar const *arg;
|
||||||
|
GFileInfo *info;
|
||||||
|
gboolean canexec;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GITG_IS_REPOSITORY (repository), FALSE);
|
||||||
|
|
||||||
|
if (repository->priv->git_dir == NULL)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
hooksdir = g_file_get_child (repository->priv->git_dir, "hooks");
|
||||||
|
hookfile = g_file_get_child (hooksdir, name);
|
||||||
|
g_object_unref (hooksdir);
|
||||||
|
|
||||||
|
info = g_file_query_info (hookfile,
|
||||||
|
G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
|
||||||
|
G_FILE_QUERY_INFO_NONE,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
canexec = info &&
|
||||||
|
g_file_info_get_attribute_boolean (info,
|
||||||
|
G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
|
||||||
|
|
||||||
|
if (info)
|
||||||
|
{
|
||||||
|
g_object_unref (info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!canexec)
|
||||||
|
{
|
||||||
|
/* It's considered a success if the hook cannot be executed */
|
||||||
|
g_object_unref (hookfile);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = g_file_get_path (hookfile);
|
||||||
|
g_object_unref (hookfile);
|
||||||
|
|
||||||
|
args = g_ptr_array_new ();
|
||||||
|
g_ptr_array_add (args, path);
|
||||||
|
|
||||||
|
va_start (ap, error);
|
||||||
|
|
||||||
|
while ((arg = va_arg (ap, gchar const *)) != NULL)
|
||||||
|
{
|
||||||
|
g_ptr_array_add (args, g_strdup (arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end (ap);
|
||||||
|
|
||||||
|
g_ptr_array_add (args, NULL);
|
||||||
|
argsv = (gchar **)g_ptr_array_free (args, FALSE);
|
||||||
|
|
||||||
|
command = gitg_command_newv (NULL,
|
||||||
|
(gchar const * const *)argsv);
|
||||||
|
|
||||||
|
g_strfreev (argsv);
|
||||||
|
|
||||||
|
retval = gitg_shell_run_sync_with_output (command,
|
||||||
|
TRUE,
|
||||||
|
&ret,
|
||||||
|
error);
|
||||||
|
|
||||||
|
if (!retval)
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
gchar *joined;
|
||||||
|
|
||||||
|
joined = g_strjoinv ("", ret);
|
||||||
|
|
||||||
|
if (*error)
|
||||||
|
{
|
||||||
|
g_prefix_error (error,
|
||||||
|
"Hook `%s' failed: %s",
|
||||||
|
name,
|
||||||
|
joined);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_set_error (error,
|
||||||
|
G_IO_ERROR,
|
||||||
|
G_IO_ERROR_FAILED,
|
||||||
|
"Hook `%s' failed: %s",
|
||||||
|
name,
|
||||||
|
joined);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (joined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_strfreev (ret);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
|
@ -103,6 +103,11 @@ gchar **gitg_repository_get_remotes (GitgRepository *repository);
|
||||||
GSList const *gitg_repository_get_ref_pushes (GitgRepository *repository, GitgRef *ref);
|
GSList const *gitg_repository_get_ref_pushes (GitgRepository *repository, GitgRef *ref);
|
||||||
gchar const **gitg_repository_get_current_selection (GitgRepository *repository);
|
gchar const **gitg_repository_get_current_selection (GitgRepository *repository);
|
||||||
|
|
||||||
|
gboolean gitg_repository_run_hook (GitgRepository *repository,
|
||||||
|
gchar const *name,
|
||||||
|
GError **error,
|
||||||
|
...) G_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GITG_REPOSITORY_H__ */
|
#endif /* __GITG_REPOSITORY_H__ */
|
||||||
|
|
|
@ -663,14 +663,16 @@ gitg_shell_get_buffer_size (GitgShell *shell)
|
||||||
return shell->priv->buffer_size;
|
return shell->priv->buffer_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar **
|
gboolean
|
||||||
gitg_shell_run_sync_with_output (GitgCommand *command,
|
gitg_shell_run_sync_with_output (GitgCommand *command,
|
||||||
gboolean preserve_line_endings,
|
gboolean preserve_line_endings,
|
||||||
GError **error)
|
gchar ***output,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GITG_IS_COMMAND (command), NULL);
|
g_return_val_if_fail (GITG_IS_COMMAND (command), FALSE);
|
||||||
|
|
||||||
return gitg_shell_run_sync_with_outputv (preserve_line_endings,
|
return gitg_shell_run_sync_with_outputv (preserve_line_endings,
|
||||||
|
output,
|
||||||
error,
|
error,
|
||||||
command,
|
command,
|
||||||
NULL);
|
NULL);
|
||||||
|
@ -687,16 +689,22 @@ collect_update (GitgShell *shell,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar **
|
gboolean
|
||||||
gitg_shell_run_sync_with_input_and_output_list (GitgCommand **commands,
|
gitg_shell_run_sync_with_input_and_output_list (GitgCommand **commands,
|
||||||
gboolean preserve_line_endings,
|
gboolean preserve_line_endings,
|
||||||
const gchar *input,
|
const gchar *input,
|
||||||
GError **error)
|
gchar ***output,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GitgShell *shell;
|
GitgShell *shell;
|
||||||
GPtrArray *ret;
|
GPtrArray *ret;
|
||||||
gboolean res;
|
gboolean res;
|
||||||
gchar **val;
|
gchar **out;
|
||||||
|
|
||||||
|
if (output)
|
||||||
|
{
|
||||||
|
*output = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
shell = gitg_shell_new_synchronized (1000);
|
shell = gitg_shell_new_synchronized (1000);
|
||||||
|
|
||||||
|
@ -722,34 +730,41 @@ gitg_shell_run_sync_with_input_and_output_list (GitgCommand **commands,
|
||||||
}
|
}
|
||||||
|
|
||||||
res = gitg_shell_run_list (shell, commands, error);
|
res = gitg_shell_run_list (shell, commands, error);
|
||||||
|
|
||||||
g_ptr_array_add (ret, NULL);
|
g_ptr_array_add (ret, NULL);
|
||||||
|
out = (gchar **)g_ptr_array_free (ret, FALSE);
|
||||||
|
|
||||||
|
if (output)
|
||||||
|
{
|
||||||
|
*output = out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_strfreev (out);
|
||||||
|
}
|
||||||
|
|
||||||
if (!res || gitg_io_get_exit_status (GITG_IO (shell)) != 0)
|
if (!res || gitg_io_get_exit_status (GITG_IO (shell)) != 0)
|
||||||
{
|
{
|
||||||
g_strfreev ((gchar **)g_ptr_array_free (ret, FALSE));
|
|
||||||
g_object_unref (shell);
|
g_object_unref (shell);
|
||||||
|
|
||||||
return NULL;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
val = (gchar **)g_ptr_array_free (ret, FALSE);
|
|
||||||
g_object_unref (shell);
|
g_object_unref (shell);
|
||||||
|
|
||||||
return val;
|
return TRUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar **
|
static gboolean
|
||||||
gitg_shell_run_sync_with_input_and_outputva (gboolean preserve_line_endings,
|
gitg_shell_run_sync_with_input_and_outputva (gboolean preserve_line_endings,
|
||||||
const gchar *input,
|
const gchar *input,
|
||||||
va_list ap,
|
gchar ***output,
|
||||||
GError **error)
|
va_list ap,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GPtrArray *commands;
|
GPtrArray *commands;
|
||||||
GitgCommand *cmd;
|
GitgCommand *cmd;
|
||||||
GitgCommand **cmds;
|
GitgCommand **cmds;
|
||||||
gchar **ret;
|
gboolean ret;
|
||||||
|
|
||||||
commands = g_ptr_array_new ();
|
commands = g_ptr_array_new ();
|
||||||
|
|
||||||
|
@ -764,44 +779,51 @@ gitg_shell_run_sync_with_input_and_outputva (gboolean preserve_line_endings
|
||||||
ret = gitg_shell_run_sync_with_input_and_output_list (cmds,
|
ret = gitg_shell_run_sync_with_input_and_output_list (cmds,
|
||||||
preserve_line_endings,
|
preserve_line_endings,
|
||||||
input,
|
input,
|
||||||
|
output,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
g_free (cmds);
|
g_free (cmds);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar **
|
static gboolean
|
||||||
gitg_shell_run_sync_with_outputva (gboolean preserve_line_endings,
|
gitg_shell_run_sync_with_outputva (gboolean preserve_line_endings,
|
||||||
va_list ap,
|
gchar ***output,
|
||||||
GError **error)
|
va_list ap,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
return gitg_shell_run_sync_with_input_and_outputva (preserve_line_endings,
|
return gitg_shell_run_sync_with_input_and_outputva (preserve_line_endings,
|
||||||
NULL,
|
NULL,
|
||||||
|
output,
|
||||||
ap,
|
ap,
|
||||||
error);
|
error);
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar **
|
gboolean
|
||||||
gitg_shell_run_sync_with_output_list (GitgCommand **commands,
|
gitg_shell_run_sync_with_output_list (GitgCommand **commands,
|
||||||
gboolean preserve_line_endings,
|
gboolean preserve_line_endings,
|
||||||
GError **error)
|
gchar ***output,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
return gitg_shell_run_sync_with_input_and_output_list (commands,
|
return gitg_shell_run_sync_with_input_and_output_list (commands,
|
||||||
preserve_line_endings,
|
preserve_line_endings,
|
||||||
NULL,
|
NULL,
|
||||||
|
output,
|
||||||
error);
|
error);
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar **
|
gboolean
|
||||||
gitg_shell_run_sync_with_outputv (gboolean preserve_line_endings,
|
gitg_shell_run_sync_with_outputv (gboolean preserve_line_endings,
|
||||||
GError **error,
|
gchar ***output,
|
||||||
|
GError **error,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
gchar **ret;
|
gboolean ret;
|
||||||
|
|
||||||
va_start (ap, error);
|
va_start (ap, error);
|
||||||
ret = gitg_shell_run_sync_with_outputva (preserve_line_endings,
|
ret = gitg_shell_run_sync_with_outputva (preserve_line_endings,
|
||||||
|
output,
|
||||||
ap,
|
ap,
|
||||||
error);
|
error);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
|
@ -822,19 +844,7 @@ gboolean
|
||||||
gitg_shell_run_sync_list (GitgCommand **commands,
|
gitg_shell_run_sync_list (GitgCommand **commands,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gchar **res;
|
return gitg_shell_run_sync_with_output_list (commands, FALSE, NULL, error);
|
||||||
|
|
||||||
res = gitg_shell_run_sync_with_output_list (commands, FALSE, error);
|
|
||||||
|
|
||||||
if (res)
|
|
||||||
{
|
|
||||||
g_strfreev (res);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
@ -842,21 +852,13 @@ gitg_shell_run_syncv (GError **error,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
gchar **res;
|
gboolean res;
|
||||||
|
|
||||||
va_start (ap, error);
|
va_start (ap, error);
|
||||||
res = gitg_shell_run_sync_with_outputva (FALSE, ap, error);
|
res = gitg_shell_run_sync_with_outputva (FALSE, NULL, ap, error);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
|
|
||||||
if (res)
|
return res;
|
||||||
{
|
|
||||||
g_strfreev (res);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
@ -874,22 +876,11 @@ gitg_shell_run_sync_with_input_list (GitgCommand **commands,
|
||||||
const gchar *input,
|
const gchar *input,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gchar **ret;
|
return gitg_shell_run_sync_with_input_and_output_list (commands,
|
||||||
|
FALSE,
|
||||||
ret = gitg_shell_run_sync_with_input_and_output_list (commands,
|
input,
|
||||||
FALSE,
|
NULL,
|
||||||
input,
|
error);
|
||||||
error);
|
|
||||||
|
|
||||||
if (ret)
|
|
||||||
{
|
|
||||||
g_strfreev (ret);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
@ -898,53 +889,50 @@ gitg_shell_run_sync_with_inputv (const gchar *input,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
gchar **ret;
|
gboolean ret;
|
||||||
|
|
||||||
va_start (ap, error);
|
va_start (ap, error);
|
||||||
ret = gitg_shell_run_sync_with_input_and_outputva (FALSE,
|
ret = gitg_shell_run_sync_with_input_and_outputva (FALSE,
|
||||||
input,
|
input,
|
||||||
|
NULL,
|
||||||
ap,
|
ap,
|
||||||
error);
|
error);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
|
|
||||||
if (ret)
|
return ret;
|
||||||
{
|
|
||||||
g_strfreev (ret);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar **
|
gboolean
|
||||||
gitg_shell_run_sync_with_input_and_output (GitgCommand *command,
|
gitg_shell_run_sync_with_input_and_output (GitgCommand *command,
|
||||||
gboolean preserve_line_endings,
|
gboolean preserve_line_endings,
|
||||||
const gchar *input,
|
const gchar *input,
|
||||||
GError **error)
|
gchar ***output,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GITG_IS_COMMAND (command), NULL);
|
g_return_val_if_fail (GITG_IS_COMMAND (command), FALSE);
|
||||||
|
|
||||||
return gitg_shell_run_sync_with_input_and_outputv (preserve_line_endings,
|
return gitg_shell_run_sync_with_input_and_outputv (preserve_line_endings,
|
||||||
input,
|
input,
|
||||||
|
output,
|
||||||
error,
|
error,
|
||||||
command,
|
command,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar **
|
gboolean
|
||||||
gitg_shell_run_sync_with_input_and_outputv (gboolean preserve_line_endings,
|
gitg_shell_run_sync_with_input_and_outputv (gboolean preserve_line_endings,
|
||||||
const gchar *input,
|
const gchar *input,
|
||||||
GError **error,
|
gchar ***output,
|
||||||
|
GError **error,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
gchar **ret;
|
gboolean ret;
|
||||||
|
|
||||||
va_start (ap, error);
|
va_start (ap, error);
|
||||||
ret = gitg_shell_run_sync_with_input_and_outputva (preserve_line_endings,
|
ret = gitg_shell_run_sync_with_input_and_outputva (preserve_line_endings,
|
||||||
input,
|
input,
|
||||||
|
output,
|
||||||
ap,
|
ap,
|
||||||
error);
|
error);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
|
|
|
@ -100,16 +100,19 @@ gboolean gitg_shell_runv (GitgShell *shell,
|
||||||
GError **error,
|
GError **error,
|
||||||
...) G_GNUC_NULL_TERMINATED;
|
...) G_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
gchar **gitg_shell_run_sync_with_output (GitgCommand *command,
|
gboolean gitg_shell_run_sync_with_output (GitgCommand *command,
|
||||||
gboolean preserve_line_endings,
|
gboolean preserve_line_endings,
|
||||||
GError **error);
|
gchar ***output,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gchar **gitg_shell_run_sync_with_output_list (GitgCommand **commands,
|
gboolean gitg_shell_run_sync_with_output_list (GitgCommand **commands,
|
||||||
gboolean preserve_line_endings,
|
gboolean preserve_line_endings,
|
||||||
GError **error);
|
gchar ***output,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gchar **gitg_shell_run_sync_with_outputv (gboolean preserve_line_endings,
|
gboolean gitg_shell_run_sync_with_outputv (gboolean preserve_line_endings,
|
||||||
GError **error,
|
gchar ***output,
|
||||||
|
GError **error,
|
||||||
...) G_GNUC_NULL_TERMINATED;
|
...) G_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
gboolean gitg_shell_run_sync (GitgCommand *command,
|
gboolean gitg_shell_run_sync (GitgCommand *command,
|
||||||
|
@ -133,19 +136,22 @@ gboolean gitg_shell_run_sync_with_inputv (const gchar *input,
|
||||||
GError **error,
|
GError **error,
|
||||||
...) G_GNUC_NULL_TERMINATED;
|
...) G_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
gchar **gitg_shell_run_sync_with_input_and_output (GitgCommand *command,
|
gboolean gitg_shell_run_sync_with_input_and_output (GitgCommand *command,
|
||||||
gboolean preserve_line_endings,
|
gboolean preserve_line_endings,
|
||||||
const gchar *input,
|
const gchar *input,
|
||||||
GError **error);
|
gchar ***output,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gchar **gitg_shell_run_sync_with_input_and_output_list (GitgCommand **commands,
|
gboolean gitg_shell_run_sync_with_input_and_output_list (GitgCommand **commands,
|
||||||
gboolean preserve_line_endings,
|
gboolean preserve_line_endings,
|
||||||
const gchar *input,
|
const gchar *input,
|
||||||
GError **error);
|
gchar ***output,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gchar **gitg_shell_run_sync_with_input_and_outputv (gboolean preserve_line_endings,
|
gboolean gitg_shell_run_sync_with_input_and_outputv (gboolean preserve_line_endings,
|
||||||
const gchar *input,
|
const gchar *input,
|
||||||
GError **error,
|
gchar ***output,
|
||||||
|
GError **error,
|
||||||
...) G_GNUC_NULL_TERMINATED;
|
...) G_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
@ -165,17 +165,20 @@ test_output (RepositoryInfo *info,
|
||||||
gconstpointer data)
|
gconstpointer data)
|
||||||
{
|
{
|
||||||
gchar **ret;
|
gchar **ret;
|
||||||
|
gboolean retval;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
ret = gitg_shell_run_sync_with_output (gitg_command_new (info->repository,
|
retval = gitg_shell_run_sync_with_output (gitg_command_new (info->repository,
|
||||||
"rev-parse",
|
"rev-parse",
|
||||||
"HEAD",
|
"HEAD",
|
||||||
NULL),
|
NULL),
|
||||||
FALSE,
|
FALSE,
|
||||||
&error);
|
&ret,
|
||||||
|
&error);
|
||||||
|
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
|
g_assert (retval);
|
||||||
g_assert (ret);
|
g_assert (ret);
|
||||||
g_assert (g_strv_length (ret) == 1);
|
g_assert (g_strv_length (ret) == 1);
|
||||||
|
|
||||||
|
@ -188,16 +191,19 @@ test_input (void)
|
||||||
gchar **ret;
|
gchar **ret;
|
||||||
gchar const *input = "Hello world";
|
gchar const *input = "Hello world";
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
ret = gitg_shell_run_sync_with_input_and_output (gitg_command_new (NULL,
|
retval = gitg_shell_run_sync_with_input_and_output (gitg_command_new (NULL,
|
||||||
"cat",
|
"cat",
|
||||||
"-",
|
"-",
|
||||||
NULL),
|
NULL),
|
||||||
FALSE,
|
FALSE,
|
||||||
input,
|
input,
|
||||||
&error);
|
&ret,
|
||||||
|
&error);
|
||||||
|
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
g_assert (retval);
|
||||||
g_assert (ret);
|
g_assert (ret);
|
||||||
|
|
||||||
g_assert (g_strv_length (ret) == 1);
|
g_assert (g_strv_length (ret) == 1);
|
||||||
|
@ -210,14 +216,17 @@ test_pipe (void)
|
||||||
gchar **ret;
|
gchar **ret;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gchar const *input = "Hello world";
|
gchar const *input = "Hello world";
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
ret = gitg_shell_run_sync_with_outputv (FALSE,
|
retval = gitg_shell_run_sync_with_outputv (FALSE,
|
||||||
&error,
|
&ret,
|
||||||
gitg_command_new (NULL, "echo", input, NULL),
|
&error,
|
||||||
gitg_command_new (NULL, "cat", "-", NULL),
|
gitg_command_new (NULL, "echo", input, NULL),
|
||||||
NULL);
|
gitg_command_new (NULL, "cat", "-", NULL),
|
||||||
|
NULL);
|
||||||
|
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
g_assert (retval);
|
||||||
g_assert (ret);
|
g_assert (ret);
|
||||||
|
|
||||||
g_assert (g_strv_length (ret) == 1);
|
g_assert (g_strv_length (ret) == 1);
|
||||||
|
@ -228,6 +237,7 @@ static void
|
||||||
test_pipestr (void)
|
test_pipestr (void)
|
||||||
{
|
{
|
||||||
gchar **ret;
|
gchar **ret;
|
||||||
|
gboolean retval;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gchar const *input = "Hello world";
|
gchar const *input = "Hello world";
|
||||||
gchar *cmdstr;
|
gchar *cmdstr;
|
||||||
|
@ -240,11 +250,13 @@ test_pipestr (void)
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (commands);
|
g_assert (commands);
|
||||||
|
|
||||||
ret = gitg_shell_run_sync_with_output_list (commands,
|
retval = gitg_shell_run_sync_with_output_list (commands,
|
||||||
FALSE,
|
FALSE,
|
||||||
&error);
|
&ret,
|
||||||
|
&error);
|
||||||
|
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
g_assert (retval);
|
||||||
g_assert (ret);
|
g_assert (ret);
|
||||||
|
|
||||||
g_assert (g_strv_length (ret) == 1);
|
g_assert (g_strv_length (ret) == 1);
|
||||||
|
|
Loading…
Reference in a new issue