1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2008 <jrliggett@cox.net>
6 * anjuta is free software.
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
13 * anjuta is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with anjuta. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #include "git-commit-command.h"
27 struct _GitCommitCommandPriv
31 gboolean resolve_merge
;
37 G_DEFINE_TYPE (GitCommitCommand
, git_commit_command
, GIT_TYPE_COMMAND
);
40 git_commit_command_run (AnjutaCommand
*command
)
42 GitCommitCommand
*self
;
45 self
= GIT_COMMIT_COMMAND (command
);
47 git_command_add_arg (GIT_COMMAND (self
), "commit");
49 if (self
->priv
->amend
)
50 git_command_add_arg (GIT_COMMAND (self
), "--amend");
52 if (self
->priv
->author_name
&& self
->priv
->author_email
)
54 author
= g_strdup_printf ("--author=%s <%s>", self
->priv
->author_name
,
55 self
->priv
->author_email
);
56 git_command_add_arg (GIT_COMMAND (self
), author
);
61 git_command_add_arg (GIT_COMMAND (self
), "-m");
62 git_command_add_arg (GIT_COMMAND (self
), self
->priv
->log
);
64 if (self
->priv
->resolve_merge
)
65 git_command_add_arg (GIT_COMMAND (self
), "-i");
67 git_command_add_list_to_args (GIT_COMMAND (self
), self
->priv
->paths
);
73 git_commit_command_init (GitCommitCommand
*self
)
75 self
->priv
= g_new0 (GitCommitCommandPriv
, 1);
79 git_commit_command_finalize (GObject
*object
)
81 GitCommitCommand
*self
;
83 self
= GIT_COMMIT_COMMAND (object
);
85 anjuta_util_glist_strings_free (self
->priv
->paths
);
86 g_free (self
->priv
->log
);
87 g_free (self
->priv
->author_name
);
88 g_free (self
->priv
->author_email
);
91 G_OBJECT_CLASS (git_commit_command_parent_class
)->finalize (object
);
95 git_commit_command_class_init (GitCommitCommandClass
*klass
)
97 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
98 GitCommandClass
* parent_class
= GIT_COMMAND_CLASS (klass
);
99 AnjutaCommandClass
* command_class
= ANJUTA_COMMAND_CLASS (klass
);
101 object_class
->finalize
= git_commit_command_finalize
;
102 parent_class
->output_handler
= git_command_send_output_to_info
;
103 command_class
->run
= git_commit_command_run
;
108 git_commit_command_new (const gchar
*working_directory
, gboolean amend
,
109 gboolean resolve_merge
, const gchar
*log
,
110 const gchar
*author_name
,
111 const gchar
*author_email
,
114 GitCommitCommand
*self
;
116 self
= g_object_new (GIT_TYPE_COMMIT_COMMAND
,
117 "working-directory", working_directory
,
118 "single-line-output", TRUE
,
121 self
->priv
->paths
= git_command_copy_string_list (paths
);
122 self
->priv
->amend
= amend
;
123 self
->priv
->resolve_merge
= resolve_merge
;
124 self
->priv
->log
= g_strdup (log
);
125 self
->priv
->author_name
= g_strdup (author_name
);
126 self
->priv
->author_email
= g_strdup (author_email
);