From: Junio C Hamano <gitster@pobox.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: Jeff King <peff@peff.net>, git@vger.kernel.org
Subject: Subject: [PATCH] Push to create
Date: Mon, 02 Mar 2009 22:50:46 -0800 [thread overview]
Message-ID: <7vwsb7gkvt.fsf_-_@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20090301170436.GA14365@spearce.org> (Shawn O. Pearce's message of "Sun, 1 Mar 2009 09:04:36 -0800")
This teaches receive-pack to create a new directory as a bare repository
when a user tries to push into a directory that does not exist.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
"Shawn O. Pearce" <spearce@spearce.org> writes:
> But I think that's only true for situations where you are likely the
> owner of the repository in your own home directory, such as ~you
> on kernel.org. For "hosted repositories" like any of the systems
> you described above, there is a lot more to the creation than just
> executing "git init" somewhere.
> .
> For the usage of
> creating a new repository in your own home directory on some remote
> server, why isn't this just an option to git push?
I am not at all convinced that the use case people would for whatever
reason do not want to "ssh-in, create and then push from here" is limited
to "your own playpen in your $HOME", but it certainly limits the
complexity and the scope of the damage.
builtin-receive-pack.c | 29 ++++++++++++++++++++++++++++-
t/t5541-push-create.sh | 20 ++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletions(-)
create mode 100755 t/t5541-push-create.sh
diff --git a/builtin-receive-pack.c b/builtin-receive-pack.c
index 849f1fe..2f2831c 100644
--- a/builtin-receive-pack.c
+++ b/builtin-receive-pack.c
@@ -652,6 +652,33 @@ static void add_alternate_refs(void)
foreach_alt_odb(add_refs_from_alternate, NULL);
}
+static char *create_new_repo(char *dir)
+{
+ struct child_process child;
+ const char *argv[20];
+ int argc;
+
+ if (mkdir(dir, 0777)) {
+ error("cannot mkdir '%s': %s", dir, strerror(errno));
+ return NULL;
+ }
+ argc = 0;
+ argv[argc++] = "init";
+ argv[argc++] = "--bare";
+ argv[argc++] = NULL;
+ child.argv = argv;
+ if (run_command_v_opt_cd_env(argv,
+ RUN_COMMAND_NO_STDIN |
+ RUN_COMMAND_STDOUT_TO_STDERR |
+ RUN_GIT_CMD,
+ dir,
+ NULL)) {
+ error("cannot run git init");
+ return NULL;
+ }
+ return enter_repo(dir, 0);
+}
+
int cmd_receive_pack(int argc, const char **argv, const char *prefix)
{
int i;
@@ -674,7 +701,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
setup_path();
- if (!enter_repo(dir, 0))
+ if (!enter_repo(dir, 0) && !create_new_repo(dir))
die("'%s': unable to chdir or not a git archive", dir);
if (is_repository_shallow())
diff --git a/t/t5541-push-create.sh b/t/t5541-push-create.sh
new file mode 100755
index 0000000..52558a5
--- /dev/null
+++ b/t/t5541-push-create.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+test_description='push into nonexisting repository'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+ test_commit A &&
+ test_commit B &&
+ test_commit C
+'
+
+test_expect_success 'push into nonexisting repository' '
+ this=$(git rev-parse B) &&
+ git push "file://$(pwd)/not-here.git" B:refs/heads/master &&
+ that=$(GIT_DIR=not-here.git git rev-parse HEAD) &&
+ test "$this" = "$that"
+'
+
+test_done
--
1.6.2.rc2.123.gab4478
next prev parent reply other threads:[~2009-03-03 6:52 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-01 0:03 [PATCH 1/4] Refactor list of environment variables to be sanitized Junio C Hamano
2009-03-01 0:03 ` [PATCH 2/4] git-init: inject some sanity to the option parser Junio C Hamano
2009-03-01 0:03 ` [PATCH 3/4] Add init-serve, the remote side of "git init --remote=host:path" Junio C Hamano
2009-03-01 0:03 ` [PATCH 4/4] " Junio C Hamano
2009-03-01 3:16 ` [PATCH 3/4] Add init-serve, the remote side of " Jeff King
2009-03-01 5:54 ` Junio C Hamano
2009-03-01 10:00 ` Jeff King
2009-03-01 17:04 ` Shawn O. Pearce
2009-03-03 6:50 ` Junio C Hamano [this message]
2009-03-03 7:09 ` Subject: [PATCH] Push to create Jay Soffian
2009-03-03 7:09 ` Jeff King
2009-03-03 7:37 ` Jay Soffian
2009-03-03 7:39 ` Jay Soffian
2009-03-03 7:56 ` Junio C Hamano
2009-03-03 8:02 ` Jay Soffian
2009-03-03 8:04 ` Junio C Hamano
2009-03-03 8:04 ` Junio C Hamano
2009-03-03 8:16 ` Jay Soffian
2009-03-03 8:23 ` Jeff King
2009-03-03 19:57 ` Jay Soffian
2009-03-04 5:42 ` Jeff King
2009-03-04 6:35 ` Junio C Hamano
2009-03-04 13:06 ` Jay Soffian
2009-03-03 7:55 ` Junio C Hamano
2009-03-03 8:06 ` Jeff King
2009-03-03 8:22 ` Junio C Hamano
2009-03-03 8:27 ` Jeff King
2009-03-03 8:30 ` Junio C Hamano
2009-03-03 8:41 ` Jay Soffian
2009-03-03 9:23 ` Theodore Tso
2009-03-03 10:39 ` Johannes Schindelin
2009-03-04 17:58 ` Theodore Tso
2009-03-06 1:37 ` Miles Bader
2009-03-03 18:41 ` Shawn O. Pearce
2009-03-04 8:32 ` [RFC/PATCH 1/2] improve missing repository error message Jeff King
2009-03-04 9:19 ` Matthieu Moy
2009-03-04 10:35 ` Jeff King
2009-03-04 18:57 ` Shawn O. Pearce
2009-03-05 10:36 ` Jeff King
2009-03-04 8:42 ` [RFC/PATCH 2/2] make remote hangup warnings more friendly Jeff King
2009-03-04 19:04 ` Shawn O. Pearce
2009-03-05 10:45 ` Jeff King
2009-03-03 21:08 ` Subject: [PATCH] Push to create Daniel Barkalow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vwsb7gkvt.fsf_-_@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).