From 61f4ef88493cca416c6a4483aeadb104d706d648 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sun, 28 Dec 2008 13:47:12 -0500 Subject: [PATCH] Add support for launching the editor from the tree view Only supported for files in the currently checked out head. Requested by Cyril Romain. --- NEWS | 1 + tig.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 4d91c7e..361e3b0 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ Improvements: - Display repository references in the sorted order: tags, heads, tracked remotes, remotes. - Add bash completion for blame. + - Tree view: edit files of the current branch. Bug fixes: diff --git a/tig.c b/tig.c index 6e5b0b4..4216d87 100644 --- a/tig.c +++ b/tig.c @@ -495,6 +495,7 @@ static char opt_editor[SIZEOF_STR] = ""; static FILE *opt_tty = NULL; #define is_initial_commit() (!*opt_head_rev) +#define is_head_commit(rev) (!strcmp((rev), "HEAD") || !strcmp(opt_head_rev, (rev))) static enum request parse_options(int argc, const char *argv[]) @@ -3372,9 +3373,18 @@ tree_request(struct view *view, enum request request, struct line *line) } string_copy(opt_ref, view->vid); - string_format(opt_file, "%s%s", opt_path, tree_path(line)); return request; + case REQ_EDIT: + if (line->type != LINE_TREE_FILE) { + report("Edit only supported for files"); + } else if (!is_head_commit(view->vid)) { + report("Edit only supported for files in the current work tree"); + } else { + open_editor(TRUE, opt_file); + } + return REQ_NONE; + case REQ_TREE_PARENT: if (!*opt_path) { /* quit view if at top of tree */ @@ -3438,6 +3448,7 @@ tree_select(struct view *view, struct line *line) if (line->type == LINE_TREE_FILE) { string_copy_rev(ref_blob, text); + string_format(opt_file, "%s%s", opt_path, tree_path(line)); } else if (line->type != LINE_TREE_DIR) { return; -- 2.30.2