Skip to content

Commit 8f02884

Browse files
committed
status: offer *not* to lock the index and update it
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. Let's introduce the option `--no-lock-index` to prevent such problems. The idea is that the third-party tool calls `git status` with this option, preventing it from ever updating the index. 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. Note that the regression test added in this commit does not *really* verify that no index.lock file was written; that test is not possible in a portable way. Instead, we verify that .git/index is rewritten *only* when `git status` is run without `--no-lock-index`. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2b81dd8 commit 8f02884

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Documentation/git-status.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ ignored, then the directory is not shown, but all contents are shown.
134134
without options are equivalent to 'always' and 'never'
135135
respectively.
136136

137+
--no-lock-index::
138+
--lock-index::
139+
(DEPRECATED: use --no-optional-locks instead)
140+
Specifies whether `git status` should try to lock the index and
141+
update it afterwards if any changes were detected. Defaults to
142+
`--lock-index`.
143+
137144
<pathspec>...::
138145
See the 'pathspec' entry in linkgit:gitglossary[7].
139146

builtin/commit.c

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

13651365
int cmd_status(int argc, const char **argv, const char *prefix)
13661366
{
1367+
static int no_lock_index = 0;
13671368
static struct wt_status s;
13681369
int fd;
13691370
struct object_id oid;
@@ -1397,12 +1398,20 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13971398
N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
13981399
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
13991400
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
1401+
OPT_BOOL(0, "no-lock-index", &no_lock_index,
1402+
N_("do not lock the index")),
14001403
OPT_END(),
14011404
};
14021405

14031406
if (argc == 2 && !strcmp(argv[1], "-h"))
14041407
usage_with_options(builtin_status_usage, builtin_status_options);
14051408

1409+
if (no_lock_index) {
1410+
warning("--no-lock-index is deprecated, use --no-optional-locks"
1411+
" instead");
1412+
setenv(GIT_OPTIONAL_LOCKS_ENVIRONMENT, "false", 1);
1413+
}
1414+
14061415
status_init_config(&s, git_status_config);
14071416
argc = parse_options(argc, argv, prefix,
14081417
builtin_status_options,

0 commit comments

Comments
 (0)