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-ignore-command.h"
27 struct _GitIgnoreCommandPriv
32 G_DEFINE_TYPE (GitIgnoreCommand
, git_ignore_command
, GIT_TYPE_FILE_COMMAND
);
35 git_ignore_command_init (GitIgnoreCommand
*self
)
37 self
->priv
= g_new0 (GitIgnoreCommandPriv
, 1);
41 git_ignore_command_finalize (GObject
*object
)
43 GitIgnoreCommand
*self
;
45 self
= GIT_IGNORE_COMMAND (object
);
47 git_command_free_path_list (self
->priv
->paths
);
50 G_OBJECT_CLASS (git_ignore_command_parent_class
)->finalize (object
);
54 git_ignore_command_run (AnjutaCommand
*command
)
56 GitIgnoreCommand
*self
;
57 gchar
*working_directory
;
59 gchar
*ignore_file_path
;
61 GFile
*ignore_file_parent
;
62 GFile
*gitignore_file
;
63 gchar
*ignore_path_basename
;
64 GFileOutputStream
*gitignore_stream
;
66 self
= GIT_IGNORE_COMMAND (command
);
67 g_object_get (self
, "working-directory", &working_directory
, NULL
);
68 current_path
= self
->priv
->paths
;
72 ignore_file_path
= g_build_filename (working_directory
,
73 current_path
->data
, NULL
);
74 ignore_file
= g_file_new_for_path (ignore_file_path
);
75 ignore_file_parent
= g_file_get_parent (ignore_file
);
76 gitignore_file
= g_file_get_child (ignore_file_parent
, ".gitignore");
77 ignore_path_basename
= g_file_get_basename (ignore_file
);
78 gitignore_stream
= g_file_append_to (gitignore_file
, 0, NULL
, NULL
);
80 g_output_stream_write (G_OUTPUT_STREAM (gitignore_stream
),
82 strlen (ignore_path_basename
),
84 g_output_stream_write (G_OUTPUT_STREAM (gitignore_stream
),
87 g_free (ignore_file_path
);
88 g_free (ignore_path_basename
);
89 g_object_unref (ignore_file
);
90 g_object_unref (ignore_file_parent
);
91 g_object_unref (gitignore_file
);
92 g_object_unref (gitignore_stream
);
94 current_path
= g_list_next (current_path
);
97 g_free (working_directory
);
103 git_ignore_command_class_init (GitIgnoreCommandClass
*klass
)
105 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
106 AnjutaCommandClass
* command_class
= ANJUTA_COMMAND_CLASS (klass
);
108 object_class
->finalize
= git_ignore_command_finalize
;
109 command_class
->run
= git_ignore_command_run
;
114 git_ignore_command_new_path (const gchar
*working_directory
, const gchar
*path
)
116 GitIgnoreCommand
*self
;
118 self
= g_object_new (GIT_TYPE_IGNORE_COMMAND
,
119 "working-directory", working_directory
,
122 self
->priv
->paths
= g_list_append (self
->priv
->paths
, g_strdup (path
));
129 git_ignore_command_new_list (const gchar
*working_directory
, GList
*path_list
)
131 GitIgnoreCommand
*self
;
133 self
= g_object_new (GIT_TYPE_IGNORE_COMMAND
,
134 "working-directory", working_directory
,
137 self
->priv
->paths
= git_command_copy_path_list (path_list
);