Skip to content

Commit 63b6bb4

Browse files
dschovdye
authored andcommitted
Merge pull request #536: Allow --no-src during clones and git worktree after clones
These are two highly-requested items from an internal team considering a move to Scalar using Azure Repos. 1. Remove the requirement that we create a `src` directory at clone time. 2. Allow `git worktree` even when using the GVFS protocol. These are not difficult to implement. The `--no-src` option could even be submitted upstream (though the commit will need to drop one bit about an interaction with the local cache path).
2 parents 1ba930f + 2c2e5ce commit 63b6bb4

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

Documentation/scalar.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SYNOPSIS
99
--------
1010
[verse]
1111
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
12-
[--local-cache-path <path>] [--cache-server-url <url>]
12+
[--local-cache-path <path>] [--cache-server-url <url>] [--[no-]src]
1313
<url> [<enlistment>]
1414
scalar list
1515
scalar register [<enlistment>]
@@ -83,6 +83,9 @@ remote-tracking branch for the branch this option was used for the initial
8383
cloning. If the HEAD at the remote did not point at any branch when
8484
`--single-branch` clone was made, no remote-tracking branch is created.
8585

86+
--no-src::
87+
Skip adding a `src` directory within the target enlistment.
88+
8689
--[no-]full-clone::
8790
A sparse-checkout is initialized by default. This behavior can be
8891
turned off via `--full-clone`.

abspath.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int is_directory(const char *path)
1414
}
1515

1616
/* removes the last path component from 'path' except if 'path' is root */
17-
static void strip_last_component(struct strbuf *path)
17+
void strip_last_path_component(struct strbuf *path)
1818
{
1919
size_t offset = offset_1st_component(path->buf);
2020
size_t len = path->len;
@@ -119,7 +119,7 @@ static char *strbuf_realpath_1(struct strbuf *resolved, const char *path,
119119
continue; /* '.' component */
120120
} else if (next.len == 2 && !strcmp(next.buf, "..")) {
121121
/* '..' component; strip the last path component */
122-
strip_last_component(resolved);
122+
strip_last_path_component(resolved);
123123
continue;
124124
}
125125

@@ -171,7 +171,7 @@ static char *strbuf_realpath_1(struct strbuf *resolved, const char *path,
171171
* strip off the last component since it will
172172
* be replaced with the contents of the symlink
173173
*/
174-
strip_last_component(resolved);
174+
strip_last_path_component(resolved);
175175
}
176176

177177
/*

abspath.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ char *real_pathdup(const char *path, int die_on_error);
1010
const char *absolute_path(const char *path);
1111
char *absolute_pathdup(const char *path);
1212

13+
/**
14+
* Remove the last path component from 'path' except if 'path' is root.
15+
*/
16+
void strip_last_path_component(struct strbuf *path);
17+
1318
/*
1419
* Concatenate "prefix" (if len is non-zero) and "path", with no
1520
* connecting characters (so "prefix" should end with a "/").

scalar.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "trace2.h"
2323
#include "json-parser.h"
2424
#include "remote.h"
25+
#include "path.h"
2526

2627
static int is_unattended(void) {
2728
return git_env_bool("Scalar_UNATTENDED", 0);
@@ -476,8 +477,13 @@ static char *default_cache_root(const char *root)
476477
{
477478
const char *env;
478479

479-
if (is_unattended())
480-
return xstrfmt("%s/.scalarCache", root);
480+
if (is_unattended()) {
481+
struct strbuf path = STRBUF_INIT;
482+
strbuf_addstr(&path, root);
483+
strip_last_path_component(&path);
484+
strbuf_addstr(&path, "/.scalarCache");
485+
return strbuf_detach(&path, NULL);
486+
}
481487

482488
#ifdef WIN32
483489
(void)env;
@@ -701,6 +707,8 @@ static int cmd_clone(int argc, const char **argv)
701707
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
702708
const char *cache_server_url = NULL, *local_cache_root = NULL;
703709
char *default_cache_server_url = NULL, *local_cache_root_abs = NULL;
710+
const char *enlistment_parent;
711+
int no_src = 0;
704712
struct option clone_options[] = {
705713
OPT_STRING('b', "branch", &branch, N_("<branch>"),
706714
N_("branch to checkout after clone")),
@@ -709,6 +717,8 @@ static int cmd_clone(int argc, const char **argv)
709717
OPT_BOOL(0, "single-branch", &single_branch,
710718
N_("only download metadata for the branch that will "
711719
"be checked out")),
720+
OPT_BOOL(0, "no-src", &no_src,
721+
N_("skip creating a 'src' directory")),
712722
OPT_STRING(0, "cache-server-url", &cache_server_url,
713723
N_("<url>"),
714724
N_("the url or friendly name of the cache server")),
@@ -759,7 +769,13 @@ static int cmd_clone(int argc, const char **argv)
759769

760770
ensure_absolute_path(enlistment, &enlistment);
761771

762-
dir = xstrfmt("%s/src", enlistment);
772+
if (!no_src) {
773+
dir = xstrfmt("%s/src", enlistment);
774+
enlistment_parent = "../..";
775+
} else {
776+
dir = xstrdup(enlistment);
777+
enlistment_parent = "..";
778+
}
763779

764780
if (!local_cache_root)
765781
local_cache_root = local_cache_root_abs =
@@ -800,7 +816,7 @@ static int cmd_clone(int argc, const char **argv)
800816
struct strbuf path = STRBUF_INIT;
801817

802818
strbuf_addstr(&path, enlistment);
803-
if (chdir("../..") < 0 ||
819+
if (chdir(enlistment_parent) < 0 ||
804820
remove_dir_recursively(&path, 0) < 0)
805821
die(_("'--local-cache-path' cannot be inside the src "
806822
"folder;\nCould not remove '%s'"), enlistment);

t/t9210-scalar.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ test_expect_success '`scalar clone` with GVFS-enabled server' '
306306
cache_key="url_$(printf "%s" http://$HOST_PORT/ |
307307
tr A-Z a-z |
308308
test-tool sha1)" &&
309-
echo "$(pwd)/using-gvfs/.scalarCache/$cache_key" >expect &&
309+
echo "$(pwd)/.scalarCache/$cache_key" >expect &&
310310
git -C using-gvfs/src config gvfs.sharedCache >actual &&
311311
test_cmp expect actual &&
312312
@@ -391,4 +391,12 @@ test_expect_success '`scalar delete` with existing repo' '
391391
test_path_is_missing existing
392392
'
393393

394+
test_expect_success '`scalar clone --no-src`' '
395+
scalar clone --src "file://$(pwd)" with-src &&
396+
scalar clone --no-src "file://$(pwd)" without-src &&
397+
398+
test_path_is_dir with-src/src &&
399+
test_path_is_missing without-src/src
400+
'
401+
394402
test_done

0 commit comments

Comments
 (0)