Skip to content

Commit 506dbcb

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 ce4e0fa commit 506dbcb

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
@@ -145,6 +145,13 @@ ignored, then the directory is not shown, but all contents are shown.
145145
threshold.
146146
See also linkgit:git-diff[1] `--find-renames`.
147147

148+
--no-lock-index::
149+
--lock-index::
150+
(DEPRECATED: use --no-optional-locks instead)
151+
Specifies whether `git status` should try to lock the index and
152+
update it afterwards if any changes were detected. Defaults to
153+
`--lock-index`.
154+
148155
<pathspec>...::
149156
See the 'pathspec' entry in linkgit:gitglossary[7].
150157

builtin/commit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13061306
{
13071307
static int no_renames = -1;
13081308
static const char *rename_score_arg = (const char *)-1;
1309+
static int no_lock_index = 0;
13091310
static struct wt_status s;
13101311
unsigned int progress_flag = 0;
13111312
int fd;
@@ -1344,6 +1345,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13441345
{ OPTION_CALLBACK, 'M', "find-renames", &rename_score_arg,
13451346
N_("n"), N_("detect renames, optionally set similarity index"),
13461347
PARSE_OPT_OPTARG | PARSE_OPT_NONEG, opt_parse_rename_score },
1348+
OPT_BOOL(0, "no-lock-index", &no_lock_index,
1349+
N_("(DEPRECATED: use `git --no-optional-locks status` "
1350+
"instead) Do not lock the index")),
13471351
OPT_END(),
13481352
};
13491353

@@ -1357,6 +1361,12 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13571361
finalize_colopts(&s.colopts, -1);
13581362
finalize_deferred_config(&s);
13591363

1364+
if (no_lock_index) {
1365+
warning("--no-lock-index is deprecated, use --no-optional-locks"
1366+
" instead");
1367+
setenv(GIT_OPTIONAL_LOCKS_ENVIRONMENT, "false", 1);
1368+
}
1369+
13601370
handle_untracked_files_arg(&s);
13611371
handle_ignored_arg(&s);
13621372

t/t7508-status.sh

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

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

0 commit comments

Comments
 (0)