status_enter(struct view *view, struct line *line)
{
struct status *status = line->data;
- char path[SIZEOF_STR];
+ char path[SIZEOF_STR] = "";
char *info;
size_t cmdsize = 0;
- if (!status || line->type == LINE_STAT_NONE) {
- report("No file has been chosen");
+ if (line->type == LINE_STAT_NONE ||
+ (!status && line[1].type == LINE_STAT_NONE)) {
+ report("No file to diff");
return TRUE;
}
- if (sq_quote(path, 0, status->name) >= sizeof(path))
+ if (status && sq_quote(path, 0, status->name) >= sizeof(path))
return FALSE;
if (opt_cdup[0] &&
if (!string_format_from(opt_cmd, &cmdsize, STATUS_DIFF_SHOW_CMD,
"--cached", path))
return FALSE;
- info = "Staged changes to %s";
+ if (status)
+ info = "Staged changes to %s";
+ else
+ info = "Staged changes";
break;
case LINE_STAT_UNSTAGED:
if (!string_format_from(opt_cmd, &cmdsize, STATUS_DIFF_SHOW_CMD,
"", path))
return FALSE;
- info = "Unstaged changes to %s";
+ if (status)
+ info = "Unstaged changes to %s";
+ else
+ info = "Unstaged changes";
break;
case LINE_STAT_UNTRACKED:
if (opt_pipe)
return FALSE;
+
+ if (!status) {
+ report("No file to show");
+ return TRUE;
+ }
+
opt_pipe = fopen(status->name, "r");
info = "Untracked file %s";
break;
if (written != bufsize)
return FALSE;
- open_view(view, REQ_VIEW_STATUS, OPEN_RELOAD);
return TRUE;
}
status_update(struct view *view)
{
if (view == VIEW(REQ_VIEW_STATUS)) {
- struct line *line = view->lines
- ? &view->line[view->lineno] : NULL;
+ struct line *line = &view->line[view->lineno];
- if (!line || !line->data) {
- report("No file has been chosen");
- return;
- }
+ assert(view->lines);
+
+ if (!line->data) {
+ if (line[1].type == LINE_STAT_NONE) {
+ report("Nothing to update");
+ return;
+ }
- if (!status_update_file(view, line->data, line->type))
+ while (++line < view->line + view->lines && line->data) {
+ if (!status_update_file(view, line->data, line->type))
+ report("Failed to update file status");
+ }
+
+ } else if (!status_update_file(view, line->data, line->type)) {
report("Failed to update file status");
+ }
+
+ open_view(view, REQ_VIEW_STATUS, OPEN_RELOAD);
} else {
report("This action is only valid for the status view");
}