diff --git a/NEWS.adoc b/NEWS.adoc index d6a78f070..15280d6fa 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -6,7 +6,7 @@ master Bug fixes: - - Fix parsing of `--no-prefix` argument. + - Fix various issues with `diff.noprefix` and `--no-prefix`. Improvements: diff --git a/include/tig/git.h b/include/tig/git.h index 91d140f45..e14c0ba31 100644 --- a/include/tig/git.h +++ b/include/tig/git.h @@ -25,14 +25,14 @@ #define GIT_DIFF_STAGED_INITIAL(encoding_arg, context_arg, space_arg, new_name) \ GIT_DIFF_INITIAL(encoding_arg, "--cached", context_arg, space_arg, "", new_name) -#define GIT_DIFF_STAGED(encoding_arg, context_arg, space_arg, word_diff_arg, old_name, new_name) \ +#define GIT_DIFF_STAGED(encoding_arg, context_arg, prefix_arg, space_arg, word_diff_arg, old_name, new_name) \ "git", "diff-index", (encoding_arg), "--textconv", "--patch-with-stat", "-C", \ "--cached", "--diff-filter=ACDMRTXB", DIFF_ARGS, "%(cmdlineargs)", (context_arg), \ - (space_arg), (word_diff_arg), "HEAD", "--", (old_name), (new_name), NULL + (prefix_arg), (space_arg), (word_diff_arg), "HEAD", "--", (old_name), (new_name), NULL -#define GIT_DIFF_UNSTAGED(encoding_arg, context_arg, space_arg, word_diff_arg, old_name, new_name) \ +#define GIT_DIFF_UNSTAGED(encoding_arg, context_arg, prefix_arg, space_arg, word_diff_arg, old_name, new_name) \ "git", "diff-files", (encoding_arg), "--textconv", "--patch-with-stat", "-C", \ - DIFF_ARGS, "%(cmdlineargs)", (context_arg), (space_arg), (word_diff_arg), \ + DIFF_ARGS, "%(cmdlineargs)", (context_arg), (prefix_arg), (space_arg), (word_diff_arg), \ "--", (old_name), (new_name), NULL /* Don't show staged unmerged entries. */ @@ -43,9 +43,9 @@ #define GIT_DIFF_UNSTAGED_FILES(output_arg) \ "git", "diff-files", (output_arg), "%(cmdlineargs)", NULL -#define GIT_DIFF_BLAME(encoding_arg, context_arg, space_arg, word_diff_arg, new_name) \ +#define GIT_DIFF_BLAME(encoding_arg, context_arg, prefix_arg, space_arg, word_diff_arg, new_name) \ "git", "diff-files", (encoding_arg), "--textconv", "--patch-with-stat", "-C", \ - (context_arg), (space_arg), (word_diff_arg), "--", (new_name), NULL + (context_arg), (prefix_arg), (space_arg), (word_diff_arg), "--", (new_name), NULL #define GIT_DIFF_BLAME_NO_PARENT(encoding_arg, context_arg, space_arg, new_name) \ GIT_DIFF_INITIAL(encoding_arg, "", context_arg, space_arg, "/dev/null", new_name) diff --git a/include/tig/options.h b/include/tig/options.h index a17456a0c..22a9d93c8 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -199,6 +199,7 @@ const char *commit_order_arg_with_graph(enum graph_display graph_display); const char *log_custom_pretty_arg(); const char *use_mailmap_arg(); const char *diff_context_arg(); +const char *diff_prefix_arg(); const char *word_diff_arg(); const char *show_notes_arg(); diff --git a/src/blame.c b/src/blame.c index a665c18cc..9c187fbcc 100644 --- a/src/blame.c +++ b/src/blame.c @@ -431,6 +431,7 @@ blame_request(struct view *view, enum request request, struct line *line) const char *diff_parent_argv[] = { GIT_DIFF_BLAME(encoding_arg, diff_context_arg(), + diff_prefix_arg(), ignore_space_arg(), word_diff_arg(), blame->commit->filename) diff --git a/src/options.c b/src/options.c index 019318738..db72e29ab 100644 --- a/src/options.c +++ b/src/options.c @@ -140,6 +140,12 @@ diff_context_arg() return opt_diff_context_arg; } +const char * +diff_prefix_arg() +{ + return opt_diff_noprefix ? "--no-prefix" : ""; /* --default-prefix did not exist before Git 2.41. */ +} + const char * word_diff_arg() { @@ -260,7 +266,7 @@ update_options_from_argv(const char *argv[]) } if (!strcmp(flag, "--word-diff=none")) { - /* opt_word_diff = false; */ + opt_word_diff = false; mark_option_seen(&opt_word_diff); continue; } @@ -284,6 +290,12 @@ update_options_from_argv(const char *argv[]) /* Keep the flag in argv. */ } + if (!strcmp(flag, "--default-prefix")) { + opt_diff_noprefix = false; + mark_option_seen(&opt_diff_noprefix); + /* Keep the flag in argv. */ + } + argv[flags_pos++] = flag; } diff --git a/src/stage.c b/src/stage.c index 348cea362..f82aeec0e 100644 --- a/src/stage.c +++ b/src/stage.c @@ -205,6 +205,8 @@ stage_apply_chunk(struct view *view, struct line *chunk, struct line *single, if (!diff_hdr) return false; + if (opt_diff_noprefix) + apply_argv[argc++] = "-p0"; if (!revert) apply_argv[argc++] = "--cached"; if (revert || stage_line_type == LINE_STAT_STAGED) @@ -711,19 +713,21 @@ stage_open(struct view *view, enum open_flags flags) stage_status.new.name) }; const char *index_show_argv[] = { - GIT_DIFF_STAGED(encoding_arg, diff_context_arg(), ignore_space_arg(), - word_diff_arg(), stage_status.old.name, stage_status.new.name) + GIT_DIFF_STAGED(encoding_arg, diff_context_arg(), diff_prefix_arg(), + ignore_space_arg(), word_diff_arg(), stage_status.old.name, + stage_status.new.name) }; const char *files_show_argv[] = { - GIT_DIFF_UNSTAGED(encoding_arg, diff_context_arg(), ignore_space_arg(), - word_diff_arg(), stage_status.old.name, stage_status.new.name) + GIT_DIFF_UNSTAGED(encoding_arg, diff_context_arg(), diff_prefix_arg(), + ignore_space_arg(), word_diff_arg(), stage_status.old.name, + stage_status.new.name) }; /* Diffs for unmerged entries are empty when passing the new * path, so leave out the new path. */ const char *files_unmerged_argv[] = { "git", "diff-files", encoding_arg, "--textconv", "--patch-with-stat", - DIFF_ARGS, diff_context_arg(), ignore_space_arg(), "--", - stage_status.old.name, NULL + DIFF_ARGS, diff_context_arg(), diff_prefix_arg(), + ignore_space_arg(), "--", stage_status.old.name, NULL }; static const char *file_argv[] = { repo.exec_dir, stage_status.new.name, NULL }; const char **argv = NULL; diff --git a/src/stash.c b/src/stash.c index ac7b9290a..0c00868c7 100644 --- a/src/stash.c +++ b/src/stash.c @@ -81,7 +81,7 @@ stash_request(struct view *view, enum request request, struct line *line) "git", "stash", "show", encoding_arg, "--pretty=fuller", "--patch-with-stat", diff_context_arg(), ignore_space_arg(), word_diff_arg(), DIFF_ARGS, - "--no-color", "%(stash)", NULL + "%(cmdlineargs)", "--no-color", "%(stash)", NULL }; if (!argv_format(diff_view.env, &diff_view.argv, diff_argv, 0)) diff --git a/test/diff/editor-test b/test/diff/editor-test index 96377abed..7b5c6ff24 100755 --- a/test/diff/editor-test +++ b/test/diff/editor-test @@ -258,8 +258,8 @@ test_case noprefix-conflict \ ' << EOF 1| diff --cc conflict-file | index 86c5a05,b4c3de6..0000000 - | --- a/conflict-file - | +++ b/conflict-file + | --- conflict-file + | +++ conflict-file 5| @@@ -1,1 -1,1 +1,5 @@@ | ++<<<<<<< HEAD | +c' diff --git a/test/diff/submodule-editor-test b/test/diff/submodule-editor-test index 89161c94c..ec7e5811f 100755 --- a/test/diff/submodule-editor-test +++ b/test/diff/submodule-editor-test @@ -288,8 +288,8 @@ test_case noprefix-conflict \ ' << EOF 1| diff --cc conflict-file | index 86c5a05,b4c3de6..0000000 - | --- a/conflict-file - | +++ b/conflict-file + | --- conflict-file + | +++ conflict-file 5| @@@ -1,1 -1,1 +1,5 @@@ | ++<<<<<<< HEAD | +c' diff --git a/test/diff/worktree-editor-test b/test/diff/worktree-editor-test index 2e71c347d..6abcb1c74 100755 --- a/test/diff/worktree-editor-test +++ b/test/diff/worktree-editor-test @@ -283,8 +283,8 @@ test_case noprefix-conflict \ ' << EOF 1| diff --cc conflict-file | index 86c5a05,b4c3de6..0000000 - | --- a/conflict-file - | +++ b/conflict-file + | --- conflict-file + | +++ conflict-file 5| @@@ -1,1 -1,1 +1,5 @@@ | ++<<<<<<< HEAD | +c'