summaryrefslogtreecommitdiff
path: root/builtin/worktree.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-04-26 06:39:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-04-26 06:39:12 (GMT)
commite31159746e30a24d7064bf30491ccd73444eb00a (patch)
tree4fc61f845670e28417a989d24fc37e7e91d645d3 /builtin/worktree.c
parent7ba7bff6294153449453b27ebdcb2ad2e751736d (diff)
parent507e6e9eecce5e7a2cc204c844bbb2f9b17b31e3 (diff)
downloadgit-e31159746e30a24d7064bf30491ccd73444eb00a.zip
git-e31159746e30a24d7064bf30491ccd73444eb00a.tar.gz
git-e31159746e30a24d7064bf30491ccd73444eb00a.tar.bz2
Merge branch 'nd/worktree-add-lock'
Allow to lock a worktree immediately after it's created. This helps prevent a race between "git worktree add; git worktree lock" and "git worktree prune". * nd/worktree-add-lock: worktree add: add --lock option
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r--builtin/worktree.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 57caa08..1722a9b 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -24,6 +24,7 @@ struct add_opts {
int force;
int detach;
int checkout;
+ int keep_locked;
const char *new_branch;
int force_new_branch;
};
@@ -240,7 +241,10 @@ static int add_worktree(const char *path, const char *refname,
* after the preparation is over.
*/
strbuf_addf(&sb, "%s/locked", sb_repo.buf);
- write_file(sb.buf, "initializing");
+ if (!opts->keep_locked)
+ write_file(sb.buf, "initializing");
+ else
+ write_file(sb.buf, "added with --lock");
strbuf_addf(&sb_git, "%s/.git", path);
if (safe_create_leading_directories_const(sb_git.buf))
@@ -301,9 +305,11 @@ static int add_worktree(const char *path, const char *refname,
junk_git_dir = NULL;
done:
- strbuf_reset(&sb);
- strbuf_addf(&sb, "%s/locked", sb_repo.buf);
- unlink_or_warn(sb.buf);
+ if (ret || !opts->keep_locked) {
+ strbuf_reset(&sb);
+ strbuf_addf(&sb, "%s/locked", sb_repo.buf);
+ unlink_or_warn(sb.buf);
+ }
argv_array_clear(&child_env);
strbuf_release(&sb);
strbuf_release(&symref);
@@ -326,6 +332,7 @@ static int add(int ac, const char **av, const char *prefix)
N_("create or reset a branch")),
OPT_BOOL(0, "detach", &opts.detach, N_("detach HEAD at named commit")),
OPT_BOOL(0, "checkout", &opts.checkout, N_("populate the new working tree")),
+ OPT_BOOL(0, "lock", &opts.keep_locked, N_("keep the new working tree locked")),
OPT_END()
};