[PATCH v5] worktree: add: introduce --checkout option

2016-03-29 Thread Ray Zhang
By adding this option which defaults to true, we can use the
corresponding --no-checkout to make some customizations before
the checkout, like sparse checkout, etc.

Helped-by: Eric Sunshine 
Helped-by: Junio C Hamano 
Reviewed-by: Eric Sunshine 
Signed-off-by: Ray Zhang 
---
Changes since last version of this patch[v4]:
t/t2025-worktree-add.sh: use test -e to test file existence.
builtin/worktree.c: refactor the code a little bit.

[v4]: http://article.gmane.org/gmane.comp.version-control.git/290030
[v3]: http://article.gmane.org/gmane.comp.version-control.git/289877
[v2]: http://article.gmane.org/gmane.comp.version-control.git/289713
[v1]: http://article.gmane.org/gmane.comp.version-control.git/289659
---
 Documentation/git-worktree.txt |  8 +++-
 builtin/worktree.c | 29 ++---
 t/t2025-worktree-add.sh| 12 
 3 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 62c76c1..c622345 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees
 SYNOPSIS
 
 [verse]
-'git worktree add' [-f] [--detach] [-b ]  []
+'git worktree add' [-f] [--detach] [--checkout] [-b ]  
[]
 'git worktree prune' [-n] [-v] [--expire ]
 'git worktree list' [--porcelain]
 
@@ -87,6 +87,12 @@ OPTIONS
With `add`, detach HEAD in the new working tree. See "DETACHED HEAD"
in linkgit:git-checkout[1].
 
+--[no-]checkout::
+   By default, `add` checks out ``, however, `--no-checkout` can
+   be used to suppress checkout in order to make customizations,
+   such as configuring sparse-checkout. See "Sparse checkout"
+   in linkgit:git-read-tree[1].
+
 -n::
 --dry-run::
With `prune`, do not remove anything; just report what it would
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 38b5609..d8e3795 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {
 struct add_opts {
int force;
int detach;
+   int checkout;
const char *new_branch;
int force_new_branch;
 };
@@ -284,18 +285,22 @@ static int add_worktree(const char *path, const char 
*refname,
if (ret)
goto done;
 
-   cp.argv = NULL;
-   argv_array_clear(&cp.args);
-   argv_array_pushl(&cp.args, "reset", "--hard", NULL);
-   cp.env = child_env.argv;
-   ret = run_command(&cp);
-   if (!ret) {
-   is_junk = 0;
-   free(junk_work_tree);
-   free(junk_git_dir);
-   junk_work_tree = NULL;
-   junk_git_dir = NULL;
+   if (opts->checkout) {
+   cp.argv = NULL;
+   argv_array_clear(&cp.args);
+   argv_array_pushl(&cp.args, "reset", "--hard", NULL);
+   cp.env = child_env.argv;
+   ret = run_command(&cp);
+   if (ret)
+   goto done;
}
+
+   is_junk = 0;
+   free(junk_work_tree);
+   free(junk_git_dir);
+   junk_work_tree = NULL;
+   junk_git_dir = NULL;
+
 done:
strbuf_reset(&sb);
strbuf_addf(&sb, "%s/locked", sb_repo.buf);
@@ -320,10 +325,12 @@ static int add(int ac, const char **av, const char 
*prefix)
OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
   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_END()
};
 
memset(&opts, 0, sizeof(opts));
+   opts.checkout = 1;
ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
if (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)
die(_("-b, -B, and --detach are mutually exclusive"));
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
index cbfa41e..3acb992 100755
--- a/t/t2025-worktree-add.sh
+++ b/t/t2025-worktree-add.sh
@@ -213,4 +213,16 @@ test_expect_success 'local clone from linked checkout' '
( cd here-clone && git fsck )
 '
 
+test_expect_success '"add" worktree with --no-checkout' '
+   git worktree add --no-checkout -b swamp swamp &&
+   ! test -e swamp/init.t &&
+   git -C swamp reset --hard &&
+   test_cmp init.t swamp/init.t
+'
+
+test_expect_success '"add" worktree with --checkout' '
+   git worktree add --checkout -b swmap2 swamp2 &&
+   test_cmp init.t swamp2/init.t
+'
+
 test_done

--
https://github.com/git/git/pull/217
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4] worktree: add: introduce --checkout option

2016-03-28 Thread Ray Zhang
By adding this option which defaults to true, we can use the
corresponding --no-checkout to make some customizations before
the checkout, like sparse checkout, etc.

Helped-by: Eric Sunshine 
Helped-by: Junio C Hamano 
Reviewed-by: Eric Sunshine 
Signed-off-by: Ray Zhang 
---
Changes since last version of this patch[v3]:
Documentation/git-worktree.txt: HEAD --> ``
t/t2025-worktree-add.sh: fix style

[v3]: http://article.gmane.org/gmane.comp.version-control.git/289877
[v2]: http://article.gmane.org/gmane.comp.version-control.git/289713
[v1]: http://article.gmane.org/gmane.comp.version-control.git/289659
---
 Documentation/git-worktree.txt |  8 +++-
 builtin/worktree.c | 15 ++-
 t/t2025-worktree-add.sh| 13 +
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 62c76c1..c622345 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees
 SYNOPSIS
 
 [verse]
-'git worktree add' [-f] [--detach] [-b ]  []
+'git worktree add' [-f] [--detach] [--checkout] [-b ]  
[]
 'git worktree prune' [-n] [-v] [--expire ]
 'git worktree list' [--porcelain]
 
@@ -87,6 +87,12 @@ OPTIONS
With `add`, detach HEAD in the new working tree. See "DETACHED HEAD"
in linkgit:git-checkout[1].
 
+--[no-]checkout::
+   By default, `add` checks out ``, however, `--no-checkout` can
+   be used to suppress checkout in order to make customizations,
+   such as configuring sparse-checkout. See "Sparse checkout"
+   in linkgit:git-read-tree[1].
+
 -n::
 --dry-run::
With `prune`, do not remove anything; just report what it would
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 38b5609..e677cd7 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {
 struct add_opts {
int force;
int detach;
+   int checkout;
const char *new_branch;
int force_new_branch;
 };
@@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char 
*refname,
if (ret)
goto done;
 
-   cp.argv = NULL;
-   argv_array_clear(&cp.args);
-   argv_array_pushl(&cp.args, "reset", "--hard", NULL);
-   cp.env = child_env.argv;
-   ret = run_command(&cp);
+   if (opts->checkout) {
+   cp.argv = NULL;
+   argv_array_clear(&cp.args);
+   argv_array_pushl(&cp.args, "reset", "--hard", NULL);
+   cp.env = child_env.argv;
+   ret = run_command(&cp);
+   }
if (!ret) {
is_junk = 0;
free(junk_work_tree);
@@ -320,10 +323,12 @@ static int add(int ac, const char **av, const char 
*prefix)
OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
   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_END()
};
 
memset(&opts, 0, sizeof(opts));
+   opts.checkout = 1;
ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
if (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)
die(_("-b, -B, and --detach are mutually exclusive"));
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
index cbfa41e..472b811 100755
--- a/t/t2025-worktree-add.sh
+++ b/t/t2025-worktree-add.sh
@@ -213,4 +213,17 @@ test_expect_success 'local clone from linked checkout' '
( cd here-clone && git fsck )
 '
 
+test_expect_success '"add" worktree with --no-checkout' '
+   git worktree add --no-checkout -b swamp swamp &&
+   ls swamp >actual &&
+   test_line_count = 0 actual &&
+   git -C swamp reset --hard &&
+   test_cmp init.t swamp/init.t
+'
+
+test_expect_success '"add" worktree with --checkout' '
+   git worktree add --checkout -b swmap2 swamp2 &&
+   test_cmp init.t swamp2/init.t
+'
+
 test_done

--
https://github.com/git/git/pull/217
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] worktree: add: introduce --checkout option

2016-03-25 Thread Ray Zhang
By adding this option which defaults to true, we can use the
corresponding --no-checkout to make some customizations before
the checkout, like sparse checkout, etc.

Signed-off-by: Ray Zhang 
---
1. reword on `--no-checkout` in Documentation/git-worktree.txt
2. update the test for `--no-checkout`
3. add a test for `--checkout`
Previous version of this patch:[v2]

[v2]: http://article.gmane.org/gmane.comp.version-control.git/289713
---
 Documentation/git-worktree.txt |  8 +++-
 builtin/worktree.c | 15 ++-
 t/t2025-worktree-add.sh| 14 ++
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 62c76c1..c2796bb 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees
 SYNOPSIS
 
 [verse]
-'git worktree add' [-f] [--detach] [-b ]  []
+'git worktree add' [-f] [--detach] [--checkout] [-b ]  
[]
 'git worktree prune' [-n] [-v] [--expire ]
 'git worktree list' [--porcelain]
 
@@ -87,6 +87,12 @@ OPTIONS
With `add`, detach HEAD in the new working tree. See "DETACHED HEAD"
in linkgit:git-checkout[1].
 
+--[no-]checkout::
+   By default, `add` checks out HEAD, however, `--no-checkout` can
+   be used to suppress checkout in order to make customizations,
+   such as configuring sparse-checkout. See "Sparse checkout"
+   in linkgit:git-read-tree[1].
+
 -n::
 --dry-run::
With `prune`, do not remove anything; just report what it would
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 38b5609..e677cd7 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {
 struct add_opts {
int force;
int detach;
+   int checkout;
const char *new_branch;
int force_new_branch;
 };
@@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char 
*refname,
if (ret)
goto done;
 
-   cp.argv = NULL;
-   argv_array_clear(&cp.args);
-   argv_array_pushl(&cp.args, "reset", "--hard", NULL);
-   cp.env = child_env.argv;
-   ret = run_command(&cp);
+   if (opts->checkout) {
+   cp.argv = NULL;
+   argv_array_clear(&cp.args);
+   argv_array_pushl(&cp.args, "reset", "--hard", NULL);
+   cp.env = child_env.argv;
+   ret = run_command(&cp);
+   }
if (!ret) {
is_junk = 0;
free(junk_work_tree);
@@ -320,10 +323,12 @@ static int add(int ac, const char **av, const char 
*prefix)
OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
   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_END()
};
 
memset(&opts, 0, sizeof(opts));
+   opts.checkout = 1;
ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
if (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)
die(_("-b, -B, and --detach are mutually exclusive"));
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
index cbfa41e..1ff96af 100755
--- a/t/t2025-worktree-add.sh
+++ b/t/t2025-worktree-add.sh
@@ -213,4 +213,18 @@ test_expect_success 'local clone from linked checkout' '
( cd here-clone && git fsck )
 '
 
+test_expect_success '"add" worktree with --no-checkout' '
+   git worktree add --no-checkout -b swamp swamp &&
+   ls swamp >actual && test_line_count = 0 actual &&
+   (
+   cd swamp && git reset --hard &&
+   test_cmp ../init.t init.t
+   )
+'
+
+test_expect_success '"add" worktree with --checkout' '
+   git worktree add --checkout -b swmap2 swamp2 &&
+   ( cd swamp2 && test_cmp ../init.t init.t )
+'
+
 test_done

--
https://github.com/git/git/pull/217
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] worktree: add: introduce --checkout option

2016-03-23 Thread Ray Zhang
By adding this option which defaults to true, we can use the
corresponding --no-checkout to make some customizations before
the checkout, like sparse checkout, etc.

Signed-off-by: Ray Zhang 
---
 Documentation/git-worktree.txt |  6 +-
 builtin/worktree.c | 15 ++-
 t/t2025-worktree-add.sh|  5 +
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 62c76c1..e96fe0f 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees
 SYNOPSIS
 
 [verse]
-'git worktree add' [-f] [--detach] [-b ]  []
+'git worktree add' [-f] [--detach] [--checkout] [-b ]  
[]
 'git worktree prune' [-n] [-v] [--expire ]
 'git worktree list' [--porcelain]
 
@@ -87,6 +87,10 @@ OPTIONS
With `add`, detach HEAD in the new working tree. See "DETACHED HEAD"
in linkgit:git-checkout[1].
 
+--checkout::
+   Default option with `add`, populate the new working tree. Use
+   `--no-checkout` to skip the checkout.
+
 -n::
 --dry-run::
With `prune`, do not remove anything; just report what it would
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 38b5609..e677cd7 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {
 struct add_opts {
int force;
int detach;
+   int checkout;
const char *new_branch;
int force_new_branch;
 };
@@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char 
*refname,
if (ret)
goto done;
 
-   cp.argv = NULL;
-   argv_array_clear(&cp.args);
-   argv_array_pushl(&cp.args, "reset", "--hard", NULL);
-   cp.env = child_env.argv;
-   ret = run_command(&cp);
+   if (opts->checkout) {
+   cp.argv = NULL;
+   argv_array_clear(&cp.args);
+   argv_array_pushl(&cp.args, "reset", "--hard", NULL);
+   cp.env = child_env.argv;
+   ret = run_command(&cp);
+   }
if (!ret) {
is_junk = 0;
free(junk_work_tree);
@@ -320,10 +323,12 @@ static int add(int ac, const char **av, const char 
*prefix)
OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
   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_END()
};
 
memset(&opts, 0, sizeof(opts));
+   opts.checkout = 1;
ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
if (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)
die(_("-b, -B, and --detach are mutually exclusive"));
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
index cbfa41e..601f963 100755
--- a/t/t2025-worktree-add.sh
+++ b/t/t2025-worktree-add.sh
@@ -213,4 +213,9 @@ test_expect_success 'local clone from linked checkout' '
( cd here-clone && git fsck )
 '
 
+test_expect_success '"add" worktree without a checkout' '
+   git worktree add --no-checkout -b swamp swamp &&
+   ( cd swamp && git reset --hard && git fsck)
+'
+
 test_done

--
https://github.com/git/git/pull/217
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] add option -n (--no-checkout) to git-worktree add

2016-03-23 Thread Ray Zhang
By adding option -n, we can make some customizations before checkout, like 
sparse checkout, etc.

Signed-off-by: Ray Zhang 
---
 builtin/worktree.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/builtin/worktree.c b/builtin/worktree.c
index 38b5609..14ca3d9 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {
 struct add_opts {
int force;
int detach;
+   int no_checkout;
const char *new_branch;
int force_new_branch;
 };
@@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char 
*refname,
if (ret)
goto done;
 
-   cp.argv = NULL;
-   argv_array_clear(&cp.args);
-   argv_array_pushl(&cp.args, "reset", "--hard", NULL);
-   cp.env = child_env.argv;
-   ret = run_command(&cp);
+   if (!opts->no_checkout) {
+   cp.argv = NULL;
+   argv_array_clear(&cp.args);
+   argv_array_pushl(&cp.args, "reset", "--hard", NULL);
+   cp.env = child_env.argv;
+   ret = run_command(&cp);
+   }
if (!ret) {
is_junk = 0;
free(junk_work_tree);
@@ -320,6 +323,7 @@ static int add(int ac, const char **av, const char *prefix)
OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
   N_("create or reset a branch")),
OPT_BOOL(0, "detach", &opts.detach, N_("detach HEAD at named 
commit")),
+   OPT_BOOL('n', "no-checkout", &opts.no_checkout, N_("don't 
create a checkout")),
OPT_END()
};
 

--
https://github.com/git/git/pull/217
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html