summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0ad8ff2)
raw | patch | inline | side by side (parent: 0ad8ff2)
author | Nanako Shiraishi <nanako3@lavabit.com> | |
Fri, 24 Jul 2009 21:59:28 +0000 (06:59 +0900) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 25 Jul 2009 09:17:54 +0000 (02:17 -0700) |
When starting a new repository, I see my students often say
% git init newrepo
and curse git. They could say
% mkdir newrepo; cd newrepo; git init
but allowing it as an obvious short-cut may be nicer.
Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
% git init newrepo
and curse git. They could say
% mkdir newrepo; cd newrepo; git init
but allowing it as an obvious short-cut may be nicer.
Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-init.txt | patch | blob | history | |
builtin-init-db.c | patch | blob | history | |
t/t0001-init.sh | patch | blob | history |
index 7151d12f349b7c6e265d5a4631029d71028a2c7d..f081b24d9d8233677388d437b8f7e6d9402b261b 100644 (file)
SYNOPSIS
--------
-'git init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
+'git init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]] [directory]
OPTIONS
in shared repositories, so that you cannot force a non fast-forwarding push
into it.
+If you name a (possibly non-existent) directory at the end of the command
+line, the command is run inside the directory (possibly after creating it).
+
--
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 4a5600631c5800d7f9d844118f37c0672b89b581..b7f708de1f164de6fbb7b6ad9a3a95d34a426fff 100644 (file)
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
}
static const char init_db_usage[] =
-"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
+"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]] [directory]";
/*
* If you want to, you can share the DB area with any number of branches.
const char *git_dir;
const char *template_dir = NULL;
unsigned int flags = 0;
+ int bare_given = 0;
int i;
for (i = 1; i < argc; i++, argv++) {
const char *arg = argv[1];
if (!prefixcmp(arg, "--template="))
template_dir = arg+11;
- else if (!strcmp(arg, "--bare")) {
- static char git_dir[PATH_MAX+1];
- is_bare_repository_cfg = 1;
- setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
- sizeof(git_dir)), 0);
- } else if (!strcmp(arg, "--shared"))
+ else if (!strcmp(arg, "--bare"))
+ bare_given = is_bare_repository_cfg = 1;
+ else if (!strcmp(arg, "--shared"))
init_shared_repository = PERM_GROUP;
else if (!prefixcmp(arg, "--shared="))
init_shared_repository = git_config_perm("arg", arg+9);
else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
flags |= INIT_DB_QUIET;
- else
+ else if (arg[0] == '-')
usage(init_db_usage);
+ else
+ break;
}
+ if (i == argc - 1) {
+ int mkdir_tried = 0;
+ retry:
+ if (chdir(argv[1]) < 0) {
+ if (!mkdir_tried) {
+ int saved;
+ /*
+ * At this point we haven't read any configuration,
+ * and we know shared_repository should always be 0;
+ * but just in case we play safe.
+ */
+ saved = shared_repository;
+ shared_repository = 0;
+ switch (safe_create_leading_directories_const(argv[1])) {
+ case -3:
+ errno = EEXIST;
+ /* fallthru */
+ case -1:
+ die_errno("cannot mkdir %s", argv[1]);
+ break;
+ default:
+ break;
+ }
+ shared_repository = saved;
+ if (mkdir(argv[1], 0777) < 0)
+ die_errno("cannot mkdir %s", argv[1]);
+ mkdir_tried = 1;
+ goto retry;
+ }
+ die_errno("cannot chdir to %s", argv[1]);
+ }
+ } else if (i < argc - 1) {
+ usage(init_db_usage);
+ }
+ if (bare_given == 1) {
+ static char git_dir[PATH_MAX+1];
+
+ setenv(GIT_DIR_ENVIRONMENT,
+ getcwd(git_dir, sizeof(git_dir)), 0);
+ }
if (init_shared_repository != -1)
shared_repository = init_shared_repository;
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index e3d846420dc09e7b24876b291b9e546ac0628ed3..49caa29061a1adb42595aecdb0aed48ff1654883 100755 (executable)
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
)
'
+test_expect_success 'init creates a new directory' '
+ rm -fr newdir &&
+ (
+ git init newdir &&
+ test -d newdir/.git/refs
+ )
+'
+
+test_expect_success 'init creates a new bare directory' '
+ rm -fr newdir &&
+ (
+ git init --bare newdir &&
+ test -d newdir/refs
+ )
+'
+
+test_expect_success 'init recreates a directory' '
+ rm -fr newdir &&
+ (
+ mkdir newdir &&
+ git init newdir &&
+ test -d newdir/.git/refs
+ )
+'
+
+test_expect_success 'init recreates a new bare directory' '
+ rm -fr newdir &&
+ (
+ mkdir newdir &&
+ git init --bare newdir &&
+ test -d newdir/refs
+ )
+'
+
+test_expect_success 'init creates a new deep directory' '
+ rm -fr newdir &&
+ (
+ # Leading directories should honor umask while
+ # the repository itself should follow "shared"
+ umask 002 &&
+ git init --bare --shared=0660 newdir/a/b/c &&
+ test -d newdir/a/b/c/refs &&
+ ls -ld newdir/a newdir/a/b > lsab.out &&
+ ! grep -v "^drwxrw[sx]r-x" ls.out &&
+ ls -ld newdir/a/b/c > lsc.out &&
+ ! grep -v "^drwxrw[sx]---" lsc.out
+ )
+'
+
+test_expect_success 'init notices EEXIST (1)' '
+ rm -fr newdir &&
+ (
+ >newdir &&
+ test_must_fail git init newdir &&
+ test -f newdir
+ )
+'
+
+test_expect_success 'init notices EEXIST (2)' '
+ rm -fr newdir &&
+ (
+ mkdir newdir &&
+ >newdir/a
+ test_must_fail git init newdir/a/b &&
+ test -f newdir/a
+ )
+'
+
+test_expect_success POSIXPERM 'init notices EPERM' '
+ rm -fr newdir &&
+ (
+ mkdir newdir &&
+ chmod -w newdir &&
+ test_must_fail git init newdir/a/b
+ )
+'
+
test_done