Skip to content

Commit 478b1e0

Browse files
committed
status: carry the --no-lock-index option for backwards-compatibility
When a third-party tool periodically runs `git status` in order to keep track of the state of the working tree, it is a bad idea to lock the index: it might interfere with interactive commands executed by the user, e.g. when the user wants to commit files. Git for Windows introduced the `--no-lock-index` option a long time ago to fix that (it made it into Git for Windows v2.9.2(3)) by simply avoiding to write that file. The downside is that the periodic `git status` calls will be a little bit more wasteful because they may have to refresh the index repeatedly, only to throw away the updates when it exits. This cannot really be helped, though, as tools wanting to get a periodic update of the status have no way to predict when the user may want to lock the index herself. Sadly, a competing approach was submitted (by somebody who apparently has less work on their plate than this maintainer) that made it into v2.15.0 but is *different*: instead of a `git status`-only option, it is an option that comes *before* the Git command and is called differently, too. Let's give previous users a chance to upgrade to newer Git for Windows versions by handling the `--no-lock-index` option, still, though with a big fat warning. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 0cf6f62 commit 478b1e0

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Documentation/git-status.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ configuration variable documented in linkgit:git-config[1].
111111
without options are equivalent to 'always' and 'never'
112112
respectively.
113113

114+
--no-lock-index::
115+
--lock-index::
116+
(DEPRECATED: use --no-optional-locks instead)
117+
Specifies whether `git status` should try to lock the index and
118+
update it afterwards if any changes were detected. Defaults to
119+
`--lock-index`.
120+
114121
<pathspec>...::
115122
See the 'pathspec' entry in linkgit:gitglossary[7].
116123

builtin/commit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
13401340

13411341
int cmd_status(int argc, const char **argv, const char *prefix)
13421342
{
1343+
static int no_lock_index = 0;
13431344
static struct wt_status s;
13441345
int fd;
13451346
struct object_id oid;
@@ -1369,6 +1370,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13691370
N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
13701371
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
13711372
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
1373+
OPT_BOOL(0, "no-lock-index", &no_lock_index,
1374+
N_("(DEPRECATED: use `git --no-optional-locks status` "
1375+
"instead) Do not lock the index")),
13721376
OPT_END(),
13731377
};
13741378

@@ -1382,6 +1386,12 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13821386
finalize_colopts(&s.colopts, -1);
13831387
finalize_deferred_config(&s);
13841388

1389+
if (no_lock_index) {
1390+
warning("--no-lock-index is deprecated, use --no-optional-locks"
1391+
" instead");
1392+
setenv(GIT_OPTIONAL_LOCKS_ENVIRONMENT, "false", 1);
1393+
}
1394+
13851395
handle_untracked_files_arg(&s);
13861396
if (show_ignored_in_status)
13871397
s.show_ignored_files = 1;

t/t7508-status.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,17 @@ test_expect_success '"Initial commit" should not be noted in commit template' '
16711671
test_i18ngrep ! "Initial commit" output
16721672
'
16731673

1674+
test_expect_success '--no-lock-index prevents index update and is deprecated' '
1675+
test-chmtime =1234567890 .git/index &&
1676+
git status --no-lock-index 2>err &&
1677+
grep "no-lock-index is deprecated" err &&
1678+
test-chmtime -v +0 .git/index >out &&
1679+
grep ^1234567890 out &&
1680+
git status &&
1681+
test-chmtime -v +0 .git/index >out &&
1682+
! grep ^1234567890 out
1683+
'
1684+
16741685
test_expect_success '--no-optional-locks prevents index update' '
16751686
test-chmtime =1234567890 .git/index &&
16761687
git --no-optional-locks status &&

0 commit comments

Comments
 (0)