File tree 5 files changed +56
-2
lines changed
5 files changed +56
-2
lines changed Original file line number Diff line number Diff line change 6
6
contents in the work tree match the contents in the
7
7
index. This option defaults to `true` . Note that this
8
8
affects only `git diff` Porcelain, and not lower level
9
- `diff` commands such as `git diff-files` .
9
+ `diff` commands such as `git diff-files` . If
10
+ `--no-optional-locks` is set (see linkgit:git[1] for
11
+ details), the index file is not updated.
10
12
11
13
`diff.dirstat` ::
12
14
ifdef::git-diff[]
Original file line number Diff line number Diff line change @@ -190,7 +190,8 @@ If you just want to run git as if it was started in `<path>` then use
190
190
--no-optional-locks::
191
191
Do not perform optional operations that require locks. This is
192
192
equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`. This
193
- functionality is implemented for `git status` and `git describe`.
193
+ functionality is implemented for `git status`, `git describe`,
194
+ and `git diff`.
194
195
195
196
--no-advice::
196
197
Disable all advice hints from being printed.
Original file line number Diff line number Diff line change 9
9
10
10
#include "builtin.h"
11
11
#include "config.h"
12
+ #include "environment.h"
12
13
#include "ewah/ewok.h"
13
14
#include "lockfile.h"
14
15
#include "color.h"
@@ -239,6 +240,9 @@ static void refresh_index_quietly(void)
239
240
struct lock_file lock_file = LOCK_INIT ;
240
241
int fd ;
241
242
243
+ if (!use_optional_locks ())
244
+ return ;
245
+
242
246
fd = repo_hold_locked_index (the_repository , & lock_file , 0 );
243
247
if (fd < 0 )
244
248
return ;
Original file line number Diff line number Diff line change @@ -500,6 +500,7 @@ integration_tests = [
500
500
' t4067-diff-partial-clone.sh' ,
501
501
' t4068-diff-symmetric-merge-base.sh' ,
502
502
' t4069-remerge-diff.sh' ,
503
+ ' t4070-diff-auto-refresh-index.sh' ,
503
504
' t4100-apply-stat.sh' ,
504
505
' t4101-apply-nonl.sh' ,
505
506
' t4102-apply-rename.sh' ,
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ #
3
+ # Copyright (c) 2025 Benjamin Woodruff
4
+ #
5
+
6
+ test_description=' diff.autoRefreshIndex config option'
7
+
8
+ . ./test-lib.sh
9
+ . " $TEST_DIRECTORY " /lib-diff.sh
10
+
11
+ test_expect_success ' index is updated when autoRefreshIndex is true' '
12
+ >tracked &&
13
+ git add tracked &&
14
+
15
+ # stat() must change (but not file contents) to trigger an index update
16
+ test_set_magic_mtime tracked &&
17
+
18
+ # check the mtime of .git/index does not change without autoRefreshIndex
19
+ test_set_magic_mtime .git/index &&
20
+ git config diff.autoRefreshIndex false &&
21
+ git diff &&
22
+ test_is_magic_mtime .git/index &&
23
+
24
+ # but it does change when autoRefreshIndex is true (the default)
25
+ git config diff.autoRefreshIndex true &&
26
+ git diff &&
27
+ ! test_is_magic_mtime .git/index
28
+ '
29
+
30
+ test_expect_success ' --no-optional-locks overrides autoRefreshIndex' '
31
+ >tracked &&
32
+ git add tracked &&
33
+ test_set_magic_mtime tracked &&
34
+
35
+ # `--no-optional-locks` overrides `autoRefreshIndex`
36
+ test_set_magic_mtime .git/index &&
37
+ git config diff.autoRefreshIndex true &&
38
+ git --no-optional-locks diff &&
39
+
40
+ # sanity check that without `--no-optional-locks` it still updates
41
+ test_is_magic_mtime .git/index &&
42
+ git diff &&
43
+ ! test_is_magic_mtime .git/index
44
+ '
45
+
46
+ test_done
You can’t perform that action at this time.
0 commit comments