* [PATCH 1/2] clone: Add an option to set up a mirror
@ 2008-08-01 14:00 Johannes Schindelin
2008-08-01 14:01 ` [PATCH 2/2] clone --bare: Add ".git" suffix to the directory name to clone into Johannes Schindelin
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Johannes Schindelin @ 2008-08-01 14:00 UTC (permalink / raw)
To: git, gitster
The command line
$ git clone --mirror $URL
is now a short-hand for
$ git clone --bare $URL
$ (cd $(basename $URL) && git remote add --mirror origin $URL)
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
Documentation/git-clone.txt | 5 ++++-
builtin-clone.c | 9 ++++++++-
t/t5601-clone.sh | 10 ++++++++++
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 26fd1b1..0e14e73 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -10,7 +10,7 @@ SYNOPSIS
--------
[verse]
'git clone' [--template=<template_directory>]
- [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare]
+ [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
[-o <name>] [-u <upload-pack>] [--reference <repository>]
[--depth <depth>] [--] <repository> [<directory>]
@@ -106,6 +106,9 @@ then the cloned repository will become corrupt.
used, neither remote-tracking branches nor the related
configuration variables are created.
+--mirror::
+ Set up a mirror of the remote repository. This implies --bare.
+
--origin <name>::
-o <name>::
Instead of using the remote name 'origin' to keep track
diff --git a/builtin-clone.c b/builtin-clone.c
index e086a40..a45179c 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -33,7 +33,7 @@ static const char * const builtin_clone_usage[] = {
NULL
};
-static int option_quiet, option_no_checkout, option_bare;
+static int option_quiet, option_no_checkout, option_bare, option_mirror;
static int option_local, option_no_hardlinks, option_shared;
static char *option_template, *option_reference, *option_depth;
static char *option_origin = NULL;
@@ -45,6 +45,8 @@ static struct option builtin_clone_options[] = {
"don't create a checkout"),
OPT_BOOLEAN(0, "bare", &option_bare, "create a bare repository"),
OPT_BOOLEAN(0, "naked", &option_bare, "create a bare repository"),
+ OPT_BOOLEAN(0, "mirror", &option_mirror,
+ "create a mirror repository (implies bare)"),
OPT_BOOLEAN('l', "local", &option_local,
"to clone from a local repository"),
OPT_BOOLEAN(0, "no-hardlinks", &option_no_hardlinks,
@@ -359,6 +361,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (option_no_hardlinks)
use_local_hardlinks = 0;
+ if (option_mirror)
+ option_bare = 1;
+
if (option_bare) {
if (option_origin)
die("--bare and --origin %s options are incompatible.",
@@ -446,7 +451,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
} else {
snprintf(branch_top, sizeof(branch_top),
"refs/remotes/%s/", option_origin);
+ }
+ if (option_mirror || !option_bare) {
/* Configure the remote */
snprintf(key, sizeof(key), "remote.%s.url", option_origin);
git_config_set(key, repo);
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index d785b3d..4b2533f 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -70,4 +70,14 @@ test_expect_success 'clone creates intermediate directories for bare repo' '
'
+test_expect_success 'clone --mirror' '
+
+ git clone --mirror src mirror &&
+ test -f mirror/HEAD &&
+ test ! -f mirror/file &&
+ FETCH="$(cd mirror && git config remote.origin.fetch)" &&
+ test "+refs/heads/*:refs/heads/*" = "$FETCH"
+
+'
+
test_done
--
1.6.0.rc1.46.g279e5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] clone --bare: Add ".git" suffix to the directory name to clone into
2008-08-01 14:01 ` [PATCH 2/2] clone --bare: Add ".git" suffix to the directory name to clone into Johannes Schindelin
@ 2008-08-01 14:01 ` Marcus Griep
2008-08-01 15:34 ` Bert Wesarg
0 siblings, 1 reply; 9+ messages in thread
From: Marcus Griep @ 2008-08-01 14:01 UTC (permalink / raw)
To: Git Mailing List
[-- Attachment #1: Type: text/plain, Size: 2213 bytes --]
Does this patch forgo adding a ".git" suffix if one is already present?
Marcus
Johannes Schindelin wrote:
> We have a tradition that bare repositories live in directories ending
> in ".git". To make this more a convention than just a tradition, teach
> "git clone --bare" to add a ".git" suffix to the directory name.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>
> This patch is only conceptionally dependent on patch 1/2.
>
> builtin-clone.c | 10 ++++++++--
> t/t5601-clone.sh | 7 +++++++
> 2 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/builtin-clone.c b/builtin-clone.c
> index a45179c..82f5b67 100644
> --- a/builtin-clone.c
> +++ b/builtin-clone.c
> @@ -95,7 +95,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)
> return NULL;
> }
>
> -static char *guess_dir_name(const char *repo, int is_bundle)
> +static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
> {
> const char *end = repo + strlen(repo), *start;
>
> @@ -131,6 +131,12 @@ static char *guess_dir_name(const char *repo, int is_bundle)
> end -= 4;
> }
>
> + if (is_bare) {
> + char *result = xmalloc(end - start + 5);
> + sprintf(result, "%.*s.git", (int)(end - start), start);
> + return result;
> + }
> +
> return xstrndup(start, end - start);
> }
>
> @@ -388,7 +394,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
> if (argc == 2)
> dir = xstrdup(argv[1]);
> else
> - dir = guess_dir_name(repo_name, is_bundle);
> + dir = guess_dir_name(repo_name, is_bundle, option_bare);
>
> if (!stat(dir, &buf))
> die("destination directory '%s' already exists.", dir);
> diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
> index 4b2533f..e0a68ab 100755
> --- a/t/t5601-clone.sh
> +++ b/t/t5601-clone.sh
> @@ -80,4 +80,11 @@ test_expect_success 'clone --mirror' '
>
> '
>
> +test_expect_success 'clone --bare names the local repository <name>.git' '
> +
> + git clone --bare src &&
> + test -d src.git
> +
> +'
> +
> test_done
--
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 793 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] clone --bare: Add ".git" suffix to the directory name to clone into
2008-08-01 14:00 [PATCH 1/2] clone: Add an option to set up a mirror Johannes Schindelin
@ 2008-08-01 14:01 ` Johannes Schindelin
2008-08-01 14:01 ` Marcus Griep
2008-08-01 14:27 ` [PATCH 1/2] clone: Add an option to set up a mirror Miklos Vajna
2008-08-02 18:55 ` Junio C Hamano
2 siblings, 1 reply; 9+ messages in thread
From: Johannes Schindelin @ 2008-08-01 14:01 UTC (permalink / raw)
To: git, gitster
We have a tradition that bare repositories live in directories ending
in ".git". To make this more a convention than just a tradition, teach
"git clone --bare" to add a ".git" suffix to the directory name.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
This patch is only conceptionally dependent on patch 1/2.
builtin-clone.c | 10 ++++++++--
t/t5601-clone.sh | 7 +++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index a45179c..82f5b67 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -95,7 +95,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)
return NULL;
}
-static char *guess_dir_name(const char *repo, int is_bundle)
+static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
{
const char *end = repo + strlen(repo), *start;
@@ -131,6 +131,12 @@ static char *guess_dir_name(const char *repo, int is_bundle)
end -= 4;
}
+ if (is_bare) {
+ char *result = xmalloc(end - start + 5);
+ sprintf(result, "%.*s.git", (int)(end - start), start);
+ return result;
+ }
+
return xstrndup(start, end - start);
}
@@ -388,7 +394,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (argc == 2)
dir = xstrdup(argv[1]);
else
- dir = guess_dir_name(repo_name, is_bundle);
+ dir = guess_dir_name(repo_name, is_bundle, option_bare);
if (!stat(dir, &buf))
die("destination directory '%s' already exists.", dir);
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 4b2533f..e0a68ab 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -80,4 +80,11 @@ test_expect_success 'clone --mirror' '
'
+test_expect_success 'clone --bare names the local repository <name>.git' '
+
+ git clone --bare src &&
+ test -d src.git
+
+'
+
test_done
--
1.6.0.rc1.46.g279e5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] clone: Add an option to set up a mirror
2008-08-01 14:00 [PATCH 1/2] clone: Add an option to set up a mirror Johannes Schindelin
2008-08-01 14:01 ` [PATCH 2/2] clone --bare: Add ".git" suffix to the directory name to clone into Johannes Schindelin
@ 2008-08-01 14:27 ` Miklos Vajna
2008-08-02 18:55 ` Junio C Hamano
2 siblings, 0 replies; 9+ messages in thread
From: Miklos Vajna @ 2008-08-01 14:27 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, gitster
[-- Attachment #1: Type: text/plain, Size: 452 bytes --]
On Fri, Aug 01, 2008 at 04:00:45PM +0200, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>
> The command line
>
> $ git clone --mirror $URL
>
> is now a short-hand for
>
> $ git clone --bare $URL
> $ (cd $(basename $URL) && git remote add --mirror origin $URL)
Funny, someone asked exactly this on #git yesterday (IIRC), but we ended
up using clone & remote, since I didn't find clone --mirror in the man.
;-)
Thanks!
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] clone --bare: Add ".git" suffix to the directory name to clone into
2008-08-01 14:01 ` Marcus Griep
@ 2008-08-01 15:34 ` Bert Wesarg
0 siblings, 0 replies; 9+ messages in thread
From: Bert Wesarg @ 2008-08-01 15:34 UTC (permalink / raw)
To: Marcus Griep; +Cc: Git Mailing List
On Fri, Aug 1, 2008 at 16:01, Marcus Griep <marcus@griep.us> wrote:
> Does this patch forgo adding a ".git" suffix if one is already present?
No, the purpose of the guess_dir_name() function is exactly to remove
any present ".git", and more.
Bert
>
> Marcus
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] clone: Add an option to set up a mirror
2008-08-01 14:00 [PATCH 1/2] clone: Add an option to set up a mirror Johannes Schindelin
2008-08-01 14:01 ` [PATCH 2/2] clone --bare: Add ".git" suffix to the directory name to clone into Johannes Schindelin
2008-08-01 14:27 ` [PATCH 1/2] clone: Add an option to set up a mirror Miklos Vajna
@ 2008-08-02 18:55 ` Junio C Hamano
2008-08-02 19:38 ` [PATCH v2] " Johannes Schindelin
2 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2008-08-02 18:55 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> The command line
>
> $ git clone --mirror $URL
>
> is now a short-hand for
>
> $ git clone --bare $URL
> $ (cd $(basename $URL) && git remote add --mirror origin $URL)
I think this would be a useful behaviour and I am very tempted to violate
the general policy of not taking any new options nor features after -rc1.
I however notice that there are differences bewteen the above sequence and
what your code actually does:
- The "remote add --mirror" sequence tells it to mirror everything, but
the patch still mirrors only heads;
- You are not setting up "remote.*.mirror = yes" in the configuration;
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] clone: Add an option to set up a mirror
2008-08-02 18:55 ` Junio C Hamano
@ 2008-08-02 19:38 ` Johannes Schindelin
2008-08-02 19:39 ` Johannes Schindelin
2008-08-02 20:46 ` Junio C Hamano
0 siblings, 2 replies; 9+ messages in thread
From: Johannes Schindelin @ 2008-08-02 19:38 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
The command line
$ git clone --mirror $URL
is now a short-hand for
$ git clone --bare $URL
$ (cd $(basename $URL) && git remote add --mirror origin $URL)
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
Interdiff to follow.
Documentation/git-clone.txt | 5 ++++-
builtin-clone.c | 24 ++++++++++++++++++++----
t/t5601-clone.sh | 10 ++++++++++
3 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 26fd1b1..0e14e73 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -10,7 +10,7 @@ SYNOPSIS
--------
[verse]
'git clone' [--template=<template_directory>]
- [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare]
+ [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
[-o <name>] [-u <upload-pack>] [--reference <repository>]
[--depth <depth>] [--] <repository> [<directory>]
@@ -106,6 +106,9 @@ then the cloned repository will become corrupt.
used, neither remote-tracking branches nor the related
configuration variables are created.
+--mirror::
+ Set up a mirror of the remote repository. This implies --bare.
+
--origin <name>::
-o <name>::
Instead of using the remote name 'origin' to keep track
diff --git a/builtin-clone.c b/builtin-clone.c
index e086a40..ecdcefa 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -33,7 +33,7 @@ static const char * const builtin_clone_usage[] = {
NULL
};
-static int option_quiet, option_no_checkout, option_bare;
+static int option_quiet, option_no_checkout, option_bare, option_mirror;
static int option_local, option_no_hardlinks, option_shared;
static char *option_template, *option_reference, *option_depth;
static char *option_origin = NULL;
@@ -45,6 +45,8 @@ static struct option builtin_clone_options[] = {
"don't create a checkout"),
OPT_BOOLEAN(0, "bare", &option_bare, "create a bare repository"),
OPT_BOOLEAN(0, "naked", &option_bare, "create a bare repository"),
+ OPT_BOOLEAN(0, "mirror", &option_mirror,
+ "create a mirror repository (implies bare)"),
OPT_BOOLEAN('l', "local", &option_local,
"to clone from a local repository"),
OPT_BOOLEAN(0, "no-hardlinks", &option_no_hardlinks,
@@ -345,6 +347,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
char branch_top[256], key[256], value[256];
struct strbuf reflog_msg;
struct transport *transport = NULL;
+ char *src_ref_prefix = "refs/heads/";
struct refspec refspec;
@@ -359,6 +362,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (option_no_hardlinks)
use_local_hardlinks = 0;
+ if (option_mirror)
+ option_bare = 1;
+
if (option_bare) {
if (option_origin)
die("--bare and --origin %s options are incompatible.",
@@ -440,26 +446,36 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);
if (option_bare) {
- strcpy(branch_top, "refs/heads/");
+ if (option_mirror)
+ src_ref_prefix = "refs/";
+ strcpy(branch_top, src_ref_prefix);
git_config_set("core.bare", "true");
} else {
snprintf(branch_top, sizeof(branch_top),
"refs/remotes/%s/", option_origin);
+ }
+ if (option_mirror || !option_bare) {
/* Configure the remote */
+ if (option_mirror) {
+ snprintf(key, sizeof(key),
+ "remote.%s.mirror", option_origin);
+ git_config_set(key, "true");
+ }
+
snprintf(key, sizeof(key), "remote.%s.url", option_origin);
git_config_set(key, repo);
snprintf(key, sizeof(key), "remote.%s.fetch", option_origin);
snprintf(value, sizeof(value),
- "+refs/heads/*:%s*", branch_top);
+ "+%s*:%s*", src_ref_prefix, branch_top);
git_config_set_multivar(key, value, "^$", 0);
}
refspec.force = 0;
refspec.pattern = 1;
- refspec.src = "refs/heads/";
+ refspec.src = src_ref_prefix;
refspec.dst = branch_top;
if (path && !is_bundle)
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index d785b3d..9cd5ef4 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -70,4 +70,14 @@ test_expect_success 'clone creates intermediate directories for bare repo' '
'
+test_expect_success 'clone --mirror' '
+
+ git clone --mirror src mirror &&
+ test -f mirror/HEAD &&
+ test ! -f mirror/file &&
+ FETCH="$(cd mirror && git config remote.origin.fetch)" &&
+ test "+refs/*:refs/*" = "$FETCH"
+
+'
+
test_done
--
1.6.0.rc1.70.g91e1d
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] clone: Add an option to set up a mirror
2008-08-02 19:38 ` [PATCH v2] " Johannes Schindelin
@ 2008-08-02 19:39 ` Johannes Schindelin
2008-08-02 20:46 ` Junio C Hamano
1 sibling, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2008-08-02 19:39 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
The interdiff:
diff --git a/builtin-clone.c b/builtin-clone.c
index a45179c..ecdcefa 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -347,6 +347,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
char branch_top[256], key[256], value[256];
struct strbuf reflog_msg;
struct transport *transport = NULL;
+ char *src_ref_prefix = "refs/heads/";
struct refspec refspec;
@@ -445,7 +446,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);
if (option_bare) {
- strcpy(branch_top, "refs/heads/");
+ if (option_mirror)
+ src_ref_prefix = "refs/";
+ strcpy(branch_top, src_ref_prefix);
git_config_set("core.bare", "true");
} else {
@@ -455,18 +458,24 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (option_mirror || !option_bare) {
/* Configure the remote */
+ if (option_mirror) {
+ snprintf(key, sizeof(key),
+ "remote.%s.mirror", option_origin);
+ git_config_set(key, "true");
+ }
+
snprintf(key, sizeof(key), "remote.%s.url", option_origin);
git_config_set(key, repo);
snprintf(key, sizeof(key), "remote.%s.fetch", option_origin);
snprintf(value, sizeof(value),
- "+refs/heads/*:%s*", branch_top);
+ "+%s*:%s*", src_ref_prefix, branch_top);
git_config_set_multivar(key, value, "^$", 0);
}
refspec.force = 0;
refspec.pattern = 1;
- refspec.src = "refs/heads/";
+ refspec.src = src_ref_prefix;
refspec.dst = branch_top;
if (path && !is_bundle)
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 4b2533f..9cd5ef4 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -76,7 +76,7 @@ test_expect_success 'clone --mirror' '
test -f mirror/HEAD &&
test ! -f mirror/file &&
FETCH="$(cd mirror && git config remote.origin.fetch)" &&
- test "+refs/heads/*:refs/heads/*" = "$FETCH"
+ test "+refs/*:refs/*" = "$FETCH"
'
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] clone: Add an option to set up a mirror
2008-08-02 19:38 ` [PATCH v2] " Johannes Schindelin
2008-08-02 19:39 ` Johannes Schindelin
@ 2008-08-02 20:46 ` Junio C Hamano
1 sibling, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2008-08-02 20:46 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git
Thanks for a quick turnaround.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-08-02 20:47 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-01 14:00 [PATCH 1/2] clone: Add an option to set up a mirror Johannes Schindelin
2008-08-01 14:01 ` [PATCH 2/2] clone --bare: Add ".git" suffix to the directory name to clone into Johannes Schindelin
2008-08-01 14:01 ` Marcus Griep
2008-08-01 15:34 ` Bert Wesarg
2008-08-01 14:27 ` [PATCH 1/2] clone: Add an option to set up a mirror Miklos Vajna
2008-08-02 18:55 ` Junio C Hamano
2008-08-02 19:38 ` [PATCH v2] " Johannes Schindelin
2008-08-02 19:39 ` Johannes Schindelin
2008-08-02 20:46 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).