}
static void
-open_editor(struct view *view, char *file)
+open_editor(bool from_root, char *file)
{
char cmd[SIZEOF_STR];
char file_sq[SIZEOF_STR];
char *editor;
+ char *prefix = from_root ? opt_cdup : "";
editor = getenv("GIT_EDITOR");
if (!editor && *opt_editor)
editor = "vi";
if (sq_quote(file_sq, 0, file) < sizeof(file_sq) &&
- string_format(cmd, "%s %s", editor, file_sq)) {
+ string_format(cmd, "%s %s%s", editor, prefix, file_sq)) {
def_prog_mode(); /* save current tty modes */
endwin(); /* restore original tty modes */
system(cmd);
struct stat statbuf;
char exclude[SIZEOF_STR];
char cmd[SIZEOF_STR];
+ unsigned long prev_lineno = view->lineno;
size_t i;
+
for (i = 0; i < view->lines; i++)
free(view->line[i].data);
free(view->line);
- view->lines = view->line_size = 0;
+ view->lines = view->line_size = view->lineno = 0;
view->line = NULL;
if (!realloc_lines(view, view->line_size + 6))
!status_run(view, cmd, FALSE, LINE_STAT_UNTRACKED))
return FALSE;
+ /* If all went well restore the previous line number to stay in
+ * the context. */
+ if (prev_lineno < view->lines)
+ view->lineno = prev_lineno;
+ else
+ view->lineno = view->lines - 1;
+
return TRUE;
}
if (!status)
return request;
- open_editor(view, status->name);
+ open_editor(status->status != '?', status->name);
break;
case REQ_ENTER:
if (!stage_status.name[0])
return request;
- open_editor(view, stage_status.name);
+ open_editor(stage_status.status != '?', stage_status.name);
break;
case REQ_ENTER: