9 #include "../UI/StatusWindow.h" 11 #include <InterfaceKit.h> 65 size_t i, maxi = git_status_list_entrycount(status);
66 const git_status_entry *s;
67 int header = 0, changesInIndex = 0;
68 int changesInWorkDir = 0, rmInWorkDir = 0;
69 const char *old_path, *new_path;
70 BString* statusText =
new BString();
73 for (i = 0; i < maxi; ++i) {
76 s = git_status_byindex(status, i);
78 if (s->status == GIT_STATUS_CURRENT)
81 if (s->status & GIT_STATUS_WT_DELETED)
84 if (s->status & GIT_STATUS_INDEX_NEW)
85 istatus =
"new file: ";
86 if (s->status & GIT_STATUS_INDEX_MODIFIED)
87 istatus =
"modified: ";
88 if (s->status & GIT_STATUS_INDEX_DELETED)
89 istatus =
"deleted: ";
90 if (s->status & GIT_STATUS_INDEX_RENAMED)
91 istatus =
"renamed: ";
92 if (s->status & GIT_STATUS_INDEX_TYPECHANGE)
93 istatus =
"typechange:";
99 statusText->Append(
"\n");
100 statusText->Append(
"Changes to be committed:\n");
102 window->
AddItem(BString(), BString());
103 window->
AddItem(BString(
"Changes to be commited:"), BString());
108 old_path = s->head_to_index->old_file.path;
109 new_path = s->head_to_index->new_file.path;
112 if (old_path && new_path && strcmp(old_path, new_path)) {
113 text.Append(
"\t%istatus %old -> %new\n");
114 text.ReplaceFirst(
"%istatus", istatus);
115 text.ReplaceFirst(
"%old", old_path);
116 text.ReplaceFirst(
"%new", new_path);
118 window->
AddItem(text, BString(new_path));
120 text.Append(
"\t%istatus %file\n");
121 text.ReplaceFirst(
"%istatus", istatus);
122 text.ReplaceFirst(
"%file", old_path ? old_path : new_path);
124 window->
AddItem(text, BString(old_path ? old_path : new_path));
126 statusText->Append(text);
135 for (i = 0; i < maxi; ++i) {
136 char *wstatus = NULL;
138 s = git_status_byindex(status, i);
145 if (s->status == GIT_STATUS_CURRENT || s->index_to_workdir == NULL)
149 if (s->status & GIT_STATUS_WT_MODIFIED)
150 wstatus =
"modified: ";
151 if (s->status & GIT_STATUS_WT_DELETED)
152 wstatus =
"deleted: ";
153 if (s->status & GIT_STATUS_WT_RENAMED)
154 wstatus =
"renamed: ";
155 if (s->status & GIT_STATUS_WT_TYPECHANGE)
156 wstatus =
"typechange:";
162 statusText->Append(
"\n");
163 statusText->Append(
"Changes not staged for commit:\n");
166 window->
AddItem(BString(), BString());
167 window->
AddItem(BString(
"Changes not staged for commit:"),
172 old_path = s->index_to_workdir->old_file.path;
173 new_path = s->index_to_workdir->new_file.path;
176 if (old_path && new_path && strcmp(old_path, new_path)) {
177 text.Append(
"\t%wstatus %old -> %new\n");
178 text.ReplaceFirst(
"%wstatus", wstatus);
179 text.ReplaceFirst(
"%old", old_path);
180 text.ReplaceFirst(
"%new", new_path);
182 window->
AddItem(text, BString(new_path));
184 text.Append(
"\t%wstatus %file\n");
185 text.ReplaceFirst(
"%wstatus", wstatus);
186 text.ReplaceFirst(
"%file", old_path ? old_path : new_path);
188 window->
AddItem(text, BString(old_path ? old_path : new_path));
190 statusText->Append(text);
194 changesInWorkDir = 1;
200 for (i = 0; i < maxi; ++i) {
201 s = git_status_byindex(status, i);
203 if (s->status == GIT_STATUS_WT_NEW) {
206 statusText->Append(
"\n");
207 statusText->Append(
"Untracked files:\n");
210 window->
AddItem(BString(), BString());
211 window->
AddItem(BString(
"Untracked files:"), BString());
216 text.Append(
"\tuntracked: %file\n");
217 text.ReplaceFirst(
"%file" , s->index_to_workdir->old_file.path);
218 statusText->Append(text);
221 s->index_to_workdir->old_file.path));
229 for (i = 0; i < maxi; ++i) {
230 s = git_status_byindex(status, i);
232 if (s->status == GIT_STATUS_IGNORED) {
235 statusText->Append(
"\n");
236 statusText->Append(
"Ignored files:\n");
239 window->
AddItem(BString(), BString());
240 window->
AddItem(BString(
"Ignored files:"), BString());
245 text.Append(
"\t%file\n");
246 text.ReplaceFirst(
"%file" ,
247 s->index_to_workdir->old_file.path);
248 statusText->Append(text);
251 s->index_to_workdir->old_file.path));
255 if (!changesInIndex && changesInWorkDir) {
256 statusText->Append(
"\nNo changes added to commit\n");
258 window->
AddItem(BString(), BString());
259 window->
AddItem(BString(
"No changes added to commit."), BString());
263 if (statusText->Length() == 0) {
264 statusText->Append(
"No changes to current branch.\n");
266 window->
AddItem(BString(
"No changes to current branch."),
283 const char *branch = NULL;
284 git_reference *head = NULL;
286 error = git_repository_head(&head, repo);
288 if (error == GIT_EUNBORNBRANCH || error == GIT_ENOTFOUND)
291 branch = git_reference_shorthand(head);
293 printf(
"Failed to get branch.\n");
295 BString* branchText =
new BString(
"Branch: ");
296 branchText->Append((branch) ? branch :
"No Branch info");
297 branchText->Append(
"\n");
299 window->
AddItem(*branchText, BString());
301 git_reference_free(head);
315 git_repository *repo = NULL;
316 git_status_list *status;
317 struct opts o = { GIT_STATUS_OPTIONS_INIT,
fDirPath.String() };
321 o.
statusopt.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
322 o.
statusopt.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
323 GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
324 GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
327 if (git_repository_open_ext(&repo, o.
repodir, 0, NULL) != 0) {
328 const git_error* err = giterr_last();
329 printf(
"Error %d : %s\n", err->klass, err->message);
331 BString buffer(
"Error : %s");
332 buffer.ReplaceFirst(
"%s", err->message);
333 BAlert* alert =
new BAlert(
"", buffer.String(),
"Cancel",
334 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
339 if (git_repository_is_bare(repo)) {
340 BString buffer(
"Error : Cannot report status on bare repository.");
341 BAlert* alert =
new BAlert(
"", buffer.String(),
"Cancel",
342 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
347 if (git_status_list_new(&status, repo, &o.
statusopt) != 0) {
348 const git_error* err = giterr_last();
349 printf(
"Error %d : %s\n", err->klass, err->message);
351 BString buffer(
"Error : %s");
352 buffer.ReplaceFirst(
"%s", err->message);
353 BAlert* alert =
new BAlert(
"", buffer.String(),
"Cancel",
354 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
361 BString* text =
new BString(
"Current directory: %dir\n");
362 text->ReplaceFirst(
"%dir",
fDirPath.String());
363 text->Append(*branchText);
364 text->Append(*statusText);
366 git_libgit2_shutdown();
Status Options structure.
static BString * GetBranchText(git_repository *, StatusWindow *)
Constructs Branch text for current repo.
BString fDirPath
The current directory where Status option is selected.
virtual TrackGitWindow * GetWindow()
This returns pointer to the status window.
BString * GetStatusText()
Constructs the entire Status Text along with current branch for given repo.
static BString * GetStatusTextUtil(git_status_list *, StatusWindow *)
Constructs Status text for current repo.
BString fRepo
The repo/directory where command is called.
StatusWindow * fStatusWindow
The Status Window.
void AddItem(BString, BString)
Adds item to the Status list.
virtual void Execute()
Status command execution.
Status(BString, BString)
Status class Constructor.
The TrackGit Window class.
git_status_options statusopt
Header file of Status command.