Skip to content

Commit 1185a10

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 4736029 commit 1185a10

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Documentation/git-status.txt

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

114-
<pathspec>...::
115114
See the 'pathspec' entry in linkgit:gitglossary[7].
116115

117116
OUTPUT

builtin/commit.c

Lines changed: 3 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,8 @@ 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_("do not lock the index")),
13721375
OPT_END(),
13731376
};
13741377

0 commit comments

Comments
 (0)