Skip to content

Commit 6249de5

Browse files
committed
Merge branch 'jk/textconv-cache-outside-repo-fix'
The code incorrectly attempted to use textconv cache when asked, even when we are not running in a repository, which has been corrected. * jk/textconv-cache-outside-repo-fix: userdiff: skip textconv caching when not in a repository
2 parents b387623 + affe355 commit 6249de5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

t/t4042-diff-textconv-caching.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,26 @@ test_expect_success 'log notes cache and still use cache for -p' '
118118
git log --no-walk -p refs/notes/textconv/magic HEAD
119119
'
120120

121+
test_expect_success 'caching is silently ignored outside repo' '
122+
mkdir -p non-repo &&
123+
echo one >non-repo/one &&
124+
echo two >non-repo/two &&
125+
echo "* diff=test" >attr &&
126+
test_expect_code 1 \
127+
nongit git -c core.attributesFile="$PWD/attr" \
128+
-c diff.test.textconv="tr a-z A-Z <" \
129+
-c diff.test.cachetextconv=true \
130+
diff --no-index one two >actual &&
131+
cat >expect <<-\EOF &&
132+
diff --git a/one b/two
133+
index 5626abf..f719efd 100644
134+
--- a/one
135+
+++ b/two
136+
@@ -1 +1 @@
137+
-ONE
138+
+TWO
139+
EOF
140+
test_cmp expect actual
141+
'
142+
121143
test_done

userdiff.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "userdiff.h"
44
#include "attr.h"
55
#include "strbuf.h"
6+
#include "environment.h"
67

78
static struct userdiff_driver *drivers;
89
static int ndrivers;
@@ -459,7 +460,8 @@ struct userdiff_driver *userdiff_get_textconv(struct repository *r,
459460
if (!driver->textconv)
460461
return NULL;
461462

462-
if (driver->textconv_want_cache && !driver->textconv_cache) {
463+
if (driver->textconv_want_cache && !driver->textconv_cache &&
464+
have_git_dir()) {
463465
struct notes_cache *c = xmalloc(sizeof(*c));
464466
struct strbuf name = STRBUF_INIT;
465467

0 commit comments

Comments
 (0)