diff --git a/NEWS.adoc b/NEWS.adoc index f8e3f0665..b11cf8596 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -37,6 +37,7 @@ Improvements: - Add `:goto ` prompt command to go to a `git-rev-parse`d revision, e.g. `:goto some/branch` or `:goto %(commit)^2`. - Respect the XDG standard for configuration files. (GH #513) + - Resolve diff paths when `diff.noprefix` is true. (GH #487, #488) - Support for custom `strftime(3)` date formats, e.g.: set main-view-date = custom diff --git a/include/tig/options.h b/include/tig/options.h index 8933acf2a..8c205eef5 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -36,6 +36,7 @@ typedef struct view_column *view_settings; _(blob_view, view_settings, VIEW_NO_FLAGS) \ _(commit_order, enum commit_order, VIEW_LOG_LIKE) \ _(diff_context, int, VIEW_DIFF_LIKE) \ + _(diff_noprefix, bool, VIEW_NO_FLAGS) \ _(diff_options, const char **, VIEW_DIFF_LIKE) \ _(diff_view, view_settings, VIEW_NO_FLAGS) \ _(editor_line_number, bool, VIEW_NO_FLAGS) \ diff --git a/src/diff.c b/src/diff.c index b85cb71c2..f3f2c2d27 100644 --- a/src/diff.c +++ b/src/diff.c @@ -528,9 +528,18 @@ diff_get_pathname(struct view *view, struct line *line) { const struct line *header; const char *dst = NULL; - const char *prefixes[] = { " b/", "cc ", "combined " }; + const char *prefixes[] = { " b/", "diff --cc ", "diff --combined " }; int i; + if (opt_diff_noprefix) { + header = find_prev_line_by_type(view, line, LINE_DIFF_ADD_FILE); + if (!header) + return NULL; + + dst = strstr(box_text(header), "+++ "); + return dst ? dst + 4 : NULL; + } + header = find_prev_line_by_type(view, line, LINE_DIFF_HEADER); if (!header) return NULL; diff --git a/src/options.c b/src/options.c index 8b02a8599..d4e94354e 100644 --- a/src/options.c +++ b/src/options.c @@ -1395,6 +1395,9 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen else if (!strcmp(name, "core.abbrev")) parse_int(&opt_id_width, value, 0, SIZEOF_REV - 1); + else if (!strcmp(name, "diff.noprefix")) + parse_bool(&opt_diff_noprefix, value); + else if (!prefixcmp(name, "tig.color.")) set_repo_config_option(name + 10, value, option_color_command); diff --git a/test/diff/editor-test b/test/diff/editor-test index c1742485e..a1db62f8c 100755 --- a/test/diff/editor-test +++ b/test/diff/editor-test @@ -3,25 +3,102 @@ . libtest.sh . libgit.sh -steps ' - :set line-graphics = ascii - :set diff-view-line-number = yes +tigrc <>>>>>> conflict-branch + + + + + + + + + + + + + + + + + + +[stage] Unstaged changes to 'conflict-file' - line 10 of 10 100% +EOF + +run_test_cases + assert_equals 'editor.log' <>>>>>> conflict-branch EOF diff --git a/test/tools/libtest.sh b/test/tools/libtest.sh index 96cc5914c..74972d692 100644 --- a/test/tools/libtest.sh +++ b/test/tools/libtest.sh @@ -105,7 +105,7 @@ if [ -n "\$lineno" ]; then fi echo "\$@" >> "$HOME/editor.log" -sed -n -e "\${lineno}p" "\$file" >> "$HOME/editor.log" +sed -n -e "\${lineno}p" "\$file" >> "$HOME/editor.log" 2>&1 EOF cd "$output_dir" @@ -503,7 +503,7 @@ run_test_cases() test_setup for name in $(cat test-cases); do tig_script "$name" " - $(if [ -e "$name.script" ]; then cat "$name.script"; fi) + $(if [ -e "$name-script" ]; then cat "$name-script"; fi) :save-display $name.screen " if [ -e "$name-before" ]; then @@ -513,7 +513,10 @@ run_test_cases() if [ -e "$name-cwd" ]; then work_dir="$work_dir/$(cat "$name-cwd")" fi + ORIG_IFS="$IFS" + IFS=$' ' test_tig $(if [ -e "$name-args" ]; then cat "$name-args"; fi) + IFS="$ORIG_IFS" work_dir="$old_work_dir" if [ -e "$name-after" ]; then test_exec_work_dir "$SHELL" "$HOME/$name-after"