@@ -198,6 +198,18 @@ selected and output. Here fewest commits different is defined as
the number of commits which would be shown by `git log tag..input`
will be the smallest number of commits possible.
+BACKGROUND REFRESH
+------------------
+
+By default, `git describe --dirty` will automatically refresh the index,
+similar to the background refresh functionality of
+linkgit:git-status[1]. Writing out the updated index is an optimization
+that isn't strictly necessary. When `describe` is run in the background,
+the lock held during the write may conflict with other simultaneous
+processes, causing them to fail. Scripts running `describe` in the
+background should consider using `git --no-optional-locks status` (see
+linkgit:git[1] for details).
+
BUGS
----
@@ -189,7 +189,8 @@ If you just want to run git as if it was started in `<path>` then use
--no-optional-locks::
Do not perform optional operations that require locks. This is
- equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`.
+ equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`. This
+ functionality is implemented for `git status` and `git describe`.
--no-advice::
Disable all advice hints from being printed.
@@ -704,7 +704,6 @@ int cmd_describe(int argc,
} else if (dirty) {
struct lock_file index_lock = LOCK_INIT;
struct rev_info revs;
- int fd;
setup_work_tree();
prepare_repo_settings(the_repository);
@@ -712,10 +711,13 @@ int cmd_describe(int argc,
repo_read_index(the_repository);
refresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED,
NULL, NULL, NULL);
- fd = repo_hold_locked_index(the_repository,
- &index_lock, 0);
- if (0 <= fd)
- repo_update_index_if_able(the_repository, &index_lock);
+ if (use_optional_locks()) {
+ int fd = repo_hold_locked_index(the_repository,
+ &index_lock, 0);
+ if (0 <= fd)
+ repo_update_index_if_able(the_repository,
+ &index_lock);
+ }
repo_init_revisions(the_repository, &revs, prefix);
@@ -749,4 +749,12 @@ test_expect_success 'do not be fooled by invalid describe format ' '
test_must_fail git cat-file -t "refs/tags/super-invalid/./../...../ ~^:/?*[////\\\\\\&}/busted.lock-42-g"$(cat out)
'
+test_expect_success '--no-optional-locks prevents index update' '
+ test_set_magic_mtime .git/index &&
+ git --no-optional-locks describe --dirty &&
+ test_is_magic_mtime .git/index &&
+ git describe --dirty &&
+ ! test_is_magic_mtime .git/index
+'
+
test_done