diff options
author | Brandon Phillips <kelson@shysecurity.com> | 2015-01-06 11:19:58 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-01-07 09:33:11 -0800 |
commit | 9579bf1bca1905c53d3faf723183a2d8d3328be4 (patch) | |
tree | 3ac93d496f3625a2881341e694bb4c14ac7e82b6 | |
parent | b48d3f810cd0dc1c9805ea211b4a87ff9fcabdd0 (diff) | |
download | git-bp/diff-relative-config.tar.gz |
diff: teach diff.relative to give default to --relative=<value>bp/diff-relative-config
Setting diff.relative configuration variable to true makes 'git diff'
behave as if '--relative=true' was passed on the command line.
Signed-off-by: Brandon Phillips <kelson@shysecurity.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | Documentation/diff-config.txt | 6 | ||||
-rw-r--r-- | diff.c | 8 | ||||
-rwxr-xr-x | t/t4045-diff-relative.sh | 20 |
3 files changed, 34 insertions, 0 deletions
diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt index b001779520..b8a7c600c8 100644 --- a/Documentation/diff-config.txt +++ b/Documentation/diff-config.txt @@ -103,6 +103,12 @@ diff.orderfile:: one shell glob pattern per line. Can be overridden by the '-O' option to linkgit:git-diff[1]. +diff.relative:: + Show pathnames relative to the current directory and exclude + changes outside this directory; equivalent to the 'git diff' + option '--relative'. + Overridden by the '--no-relative' linkgit:git-diff[1] option. + diff.renameLimit:: The number of files to consider when performing the copy/rename detection; equivalent to the 'git diff' option '-l'. @@ -223,6 +223,14 @@ int git_diff_ui_config(const char *var, const char *value, void *cb) return 0; } + if (!strcmp(var, "diff.relative")) { + if (git_config_bool(var, value)) + DIFF_OPT_SET(&default_diff_options, RELATIVE_NAME); + else + DIFF_OPT_CLR(&default_diff_options, RELATIVE_NAME); + return 0; + } + if (git_color_config(var, value, cb) < 0) return -1; diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh index ccd67c77ba..c2c15e4cf5 100755 --- a/t/t4045-diff-relative.sh +++ b/t/t4045-diff-relative.sh @@ -104,10 +104,30 @@ test_expect_success "--raw $*" " " } +check_config() { +store_diff_relative $1; shift +test_expect_success "git-config diff.relative=true in $1" " + (cd $1; git -c diff.relative=true diff -p HEAD^ >../actual) && + test_cmp expected actual +" +} + +check_config_no_relative() { +store_diff_absolute $1; shift +test_expect_success "--no-relative w/ git-config diff.relative=true in $1" " + (cd $1; git -c diff.relative=true diff --no-relative -p HEAD^ >../actual) && + test_cmp expected actual +" +} + for type in diff numstat stat raw norel_pre norel_post; do check_$type file2 --relative=subdir/ check_$type file2 --relative=subdir check_$type dir/file2 --relative=sub done +for type in config config_no_relative; do + check_$type file2 subdir/ + check_$type file2 subdir +done test_done |