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..55f73d3de 100644 --- a/include/tig/git.h +++ b/include/tig/git.h @@ -18,21 +18,21 @@ * Argv-style git command macros. */ -#define GIT_DIFF_INITIAL(encoding_arg, cached_arg, context_arg, space_arg, old_name, new_name) \ +#define GIT_DIFF_INITIAL(encoding_arg, cached_arg, context_arg, prefix_arg, space_arg, old_name, new_name) \ "git", "diff", (encoding_arg), "--no-color", "--patch-with-stat", \ - (cached_arg), (context_arg), (space_arg), "--", (old_name), (new_name), NULL + (cached_arg), (context_arg), (prefix_arg), (space_arg), "--", (old_name), (new_name), NULL -#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_INITIAL(encoding_arg, context_arg, prefix_arg, space_arg, new_name) \ + GIT_DIFF_INITIAL(encoding_arg, "--cached", context_arg, prefix_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,12 +43,12 @@ #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) +#define GIT_DIFF_BLAME_NO_PARENT(encoding_arg, context_arg, prefix_arg, space_arg, new_name) \ + GIT_DIFF_INITIAL(encoding_arg, "", context_arg, prefix_arg, space_arg, "/dev/null", new_name) #define GIT_MAIN_LOG(encoding_arg, commit_order_arg, mainargs, diffargs, revargs, fileargs, show_notes_arg, pretty_arg) \ "git", "log", (encoding_arg), \ 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..e99d35d17 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) @@ -438,6 +439,7 @@ blame_request(struct view *view, enum request request, struct line *line) const char *diff_no_parent_argv[] = { GIT_DIFF_BLAME_NO_PARENT(encoding_arg, diff_context_arg(), + diff_prefix_arg(), ignore_space_arg(), blame->commit->filename) }; diff --git a/src/diff.c b/src/diff.c index 13c973d46..ce0b07a4b 100644 --- a/src/diff.c +++ b/src/diff.c @@ -28,9 +28,10 @@ diff_open(struct view *view, enum open_flags flags) const char *diff_argv[] = { "git", "show", encoding_arg, "--pretty=fuller", "--root", "--patch-with-stat", use_mailmap_arg(), - show_notes_arg(), diff_context_arg(), ignore_space_arg(), - DIFF_ARGS, "%(cmdlineargs)", "--no-color", word_diff_arg(), - "%(commit)", "--", "%(fileargs)", NULL + show_notes_arg(), diff_context_arg(), diff_prefix_arg(), + ignore_space_arg(), DIFF_ARGS, "%(cmdlineargs)", + "--no-color", word_diff_arg(), "%(commit)", "--", + "%(fileargs)", NULL }; enum status_code code; diff --git a/src/options.c b/src/options.c index 019318738..4ee8efc2c 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"; +} + const char * word_diff_arg() { @@ -259,6 +265,18 @@ update_options_from_argv(const char *argv[]) continue; } + if (!strcmp(flag, "--no-prefix")) { + opt_diff_noprefix = true; + mark_option_seen(&opt_diff_noprefix); + continue; + } + + if (!strcmp(flag, "--default-prefix")) { + /* opt_diff_noprefix = false; */ + mark_option_seen(&opt_diff_noprefix); + continue; + } + if (!strcmp(flag, "--word-diff=none")) { /* opt_word_diff = false; */ mark_option_seen(&opt_word_diff); @@ -278,12 +296,6 @@ update_options_from_argv(const char *argv[]) /* Keep the flag in argv. */ } - if (!strcmp(flag, "--no-prefix")) { - opt_diff_noprefix = true; - 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..de355c5b4 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) @@ -707,23 +709,25 @@ static enum status_code stage_open(struct view *view, enum open_flags flags) { const char *no_head_diff_argv[] = { - GIT_DIFF_STAGED_INITIAL(encoding_arg, diff_context_arg(), ignore_space_arg(), - stage_status.new.name) + GIT_DIFF_STAGED_INITIAL(encoding_arg, diff_context_arg(), diff_prefix_arg(), + ignore_space_arg(), 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..7cf456f03 100644 --- a/src/stash.c +++ b/src/stash.c @@ -80,8 +80,9 @@ stash_request(struct view *view, enum request request, struct line *line) const char *diff_argv[] = { "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 + diff_prefix_arg(), ignore_space_arg(), + word_diff_arg(), DIFF_ARGS, "--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'