Skip to content

Commit 479adf9

Browse files
committed
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 6fb63a8 + 46ae63f commit 479adf9

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-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
@@ -12,7 +12,7 @@ int is_directory(const char *path)
1212
}
1313

1414
/* removes the last path component from 'path' except if 'path' is root */
15-
static void strip_last_component(struct strbuf *path)
15+
void strip_last_path_component(struct strbuf *path)
1616
{
1717
size_t offset = offset_1st_component(path->buf);
1818
size_t len = path->len;
@@ -117,7 +117,7 @@ static char *strbuf_realpath_1(struct strbuf *resolved, const char *path,
117117
continue; /* '.' component */
118118
} else if (next.len == 2 && !strcmp(next.buf, "..")) {
119119
/* '..' component; strip the last path component */
120-
strip_last_component(resolved);
120+
strip_last_path_component(resolved);
121121
continue;
122122
}
123123

@@ -169,7 +169,7 @@ static char *strbuf_realpath_1(struct strbuf *resolved, const char *path,
169169
* strip off the last component since it will
170170
* be replaced with the contents of the symlink
171171
*/
172-
strip_last_component(resolved);
172+
strip_last_path_component(resolved);
173173
}
174174

175175
/*

path.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ const char *git_path_auto_merge(struct repository *r);
179179
const char *git_path_fetch_head(struct repository *r);
180180
const char *git_path_shallow(struct repository *r);
181181

182+
/**
183+
* Remove the last path component from 'path' except if 'path' is root.
184+
*/
185+
void strip_last_path_component(struct strbuf *path);
182186

183187
int ends_with_path_components(const char *path, const char *components);
184188

scalar.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "help.h"
1717
#include "json-parser.h"
1818
#include "remote.h"
19+
#include "path.h"
1920

2021
static int is_unattended(void) {
2122
return git_env_bool("Scalar_UNATTENDED", 0);
@@ -469,8 +470,13 @@ static char *default_cache_root(const char *root)
469470
{
470471
const char *env;
471472

472-
if (is_unattended())
473-
return xstrfmt("%s/.scalarCache", root);
473+
if (is_unattended()) {
474+
struct strbuf path = STRBUF_INIT;
475+
strbuf_addstr(&path, root);
476+
strip_last_path_component(&path);
477+
strbuf_addstr(&path, "/.scalarCache");
478+
return strbuf_detach(&path, NULL);
479+
}
474480

475481
#ifdef WIN32
476482
(void)env;
@@ -693,6 +699,8 @@ static int cmd_clone(int argc, const char **argv)
693699
int full_clone = 0, single_branch = 0, dummy = 0;
694700
const char *cache_server_url = NULL, *local_cache_root = NULL;
695701
char *default_cache_server_url = NULL, *local_cache_root_abs = NULL;
702+
const char *enlistment_parent;
703+
int no_src = 0;
696704
struct option clone_options[] = {
697705
OPT_STRING('b', "branch", &branch, N_("<branch>"),
698706
N_("branch to checkout after clone")),
@@ -701,6 +709,8 @@ static int cmd_clone(int argc, const char **argv)
701709
OPT_BOOL(0, "single-branch", &single_branch,
702710
N_("only download metadata for the branch that will "
703711
"be checked out")),
712+
OPT_BOOL(0, "no-src", &no_src,
713+
N_("skip creating a 'src' directory")),
704714
OPT_STRING(0, "cache-server-url", &cache_server_url,
705715
N_("<url>"),
706716
N_("the url or friendly name of the cache server")),
@@ -751,7 +761,13 @@ static int cmd_clone(int argc, const char **argv)
751761

752762
ensure_absolute_path(enlistment, &enlistment);
753763

754-
dir = xstrfmt("%s/src", enlistment);
764+
if (!no_src) {
765+
dir = xstrfmt("%s/src", enlistment);
766+
enlistment_parent = "../..";
767+
} else {
768+
dir = xstrdup(enlistment);
769+
enlistment_parent = "..";
770+
}
755771

756772
if (!local_cache_root)
757773
local_cache_root = local_cache_root_abs =
@@ -792,7 +808,7 @@ static int cmd_clone(int argc, const char **argv)
792808
struct strbuf path = STRBUF_INIT;
793809

794810
strbuf_addstr(&path, enlistment);
795-
if (chdir("../..") < 0 ||
811+
if (chdir(enlistment_parent) < 0 ||
796812
remove_dir_recursively(&path, 0) < 0)
797813
die(_("'--local-cache-path' cannot be inside the src "
798814
"folder;\nCould not remove '%s'"), enlistment);

t/t9210-scalar.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ test_expect_success '`scalar clone` with GVFS-enabled server' '
299299
cache_key="url_$(printf "%s" http://$HOST_PORT/ |
300300
tr A-Z a-z |
301301
test-tool sha1)" &&
302-
echo "$(pwd)/using-gvfs/.scalarCache/$cache_key" >expect &&
302+
echo "$(pwd)/.scalarCache/$cache_key" >expect &&
303303
git -C using-gvfs/src config gvfs.sharedCache >actual &&
304304
test_cmp expect actual &&
305305
@@ -384,4 +384,12 @@ test_expect_success '`scalar delete` with existing repo' '
384384
test_path_is_missing existing
385385
'
386386

387+
test_expect_success '`scalar clone --no-src`' '
388+
scalar clone --src "file://$(pwd)" with-src &&
389+
scalar clone --no-src "file://$(pwd)" without-src &&
390+
391+
test_path_is_dir with-src/src &&
392+
test_path_is_missing without-src/src
393+
'
394+
387395
test_done

0 commit comments

Comments
 (0)