Skip to contentSkip to conversation

git-init.txt: move description section up

PATCH In review Nguyễn Thái Ngọc Duy 2 participants 4 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 git-init.txt: move description section up

It's more or less standard that synopsis is followed by description, then options.

This is not just a clean move though:

- The paragraphs are realigned a bit
- The text mentioning git-init-db is dropped. init-db is deprecated, no need to confuse new users

---
 Documentation/git-init.txt |   46 +++++++++++++++++++------------------------
 1 files changed, 20 insertions(+), 26 deletions(-)
Documentation/git-init.txt +20 -26
index 5931925..0a4a20e 100644
@@ -11,6 +11,26 @@ SYNOPSIS
 'git init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]] [directory]
 
 
+DESCRIPTION
+-----------
+
+This command creates an empty git repository - basically a `.git`
+directory with subdirectories for `objects`, `refs/heads`,
+`refs/tags`, and template files.  An initial `HEAD` file that
+references the HEAD of the master branch is also created.
+
+If the `$GIT_DIR` environment variable is set then it specifies a path
+to use instead of `./.git` for the base of the repository.
+
+If the object storage directory is specified via the
+`$GIT_OBJECT_DIRECTORY` environment variable then the sha1 directories
+are created underneath - otherwise the default `$GIT_DIR/objects`
+directory is used.
+
+Running 'git init' in an existing repository is safe. It will not
+overwrite things that are already there. The primary reason for
+rerunning 'git init' is to pick up newly added templates.
+
 OPTIONS
 -------
 
@@ -74,32 +94,6 @@ line, the command is run inside the directory (possibly after creating it).
 --
 
 
-DESCRIPTION
------------
-This command creates an empty git repository - basically a `.git` directory
-with subdirectories for `objects`, `refs/heads`, `refs/tags`, and
-template files.
-An initial `HEAD` file that references the HEAD of the master branch
-is also created.
-
-If the `$GIT_DIR` environment variable is set then it specifies a path
-to use instead of `./.git` for the base of the repository.
-
-If the object storage directory is specified via the `$GIT_OBJECT_DIRECTORY`
-environment variable then the sha1 directories are created underneath -
-otherwise the default `$GIT_DIR/objects` directory is used.
-
-Running 'git init' in an existing repository is safe. It will not overwrite
-things that are already there. The primary reason for rerunning 'git init'
-is to pick up newly added templates.
-
-Note that 'git init' is the same as 'git init-db'.  The command
-was primarily meant to initialize the object database, but over
-time it has become responsible for setting up the other aspects
-of the repository, such as installing the default hooks and
-setting the configuration variables.  The old name is retained
-for backward compatibility reasons.
-
 TEMPLATE DIRECTORY
 ------------------
 
Signature · 1 line
1.7.4.74.g639db
#1 lore raw

PATCH 2/2 init, clone: support --separate-git-dir for .git file

--separate-git-dir tells git to create git dir at the specified location, instead of where it is supposed to be. A .git file that points to that location will be put in place so that it appears normal to repo discovery process.

---
- rebased on top of master because it uses real_path().
- implemented repo move if "git init --separate-git-dir" is run on an existing repo.
- docs
- tests

 Documentation/git-clone.txt |   10 ++++++
 Documentation/git-init.txt  |   17 +++++++++-
 builtin/clone.c             |    8 ++++-
 builtin/init-db.c           |   68 +++++++++++++++++++++++++++++++++++++++++--
 cache.h                     |    1 +
 t/t0001-init.sh             |   46 +++++++++++++++++++++++++++++
 t/t5601-clone.sh            |   13 ++++++++
 7 files changed, 157 insertions(+), 6 deletions(-)
Documentation/git-clone.txt +10 -0
index 8577480..86eb4c9 100644
@@ -12,6 +12,7 @@ SYNOPSIS
 'git clone' [--template=<template_directory>]
 	  [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
 	  [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
+	  [--separate-git-dir|-L <git dir>]
 	  [--depth <depth>] [--recursive|--recurse-submodules] [--] <repository>
 	  [<directory>]
 
@@ -176,6 +177,15 @@ objects from the source repository into a pack in the cloned repository.
 	repository does not have a worktree/checkout (i.e. if any of
 	`--no-checkout`/`-n`, `--bare`, or `--mirror` is given)
 
+-L=<git dir>::
+--separate-git-dir=<git dir>::
+	Instead of placing the cloned repository where it is supposed
+	to be, place the cloned repository at the specified directory,
+	then make a filesytem-agnostic git symbolic link to there.
+	The result is git repository can be separated from working
+	tree.
+
+
 <repository>::
 	The (possibly remote) repository to clone from.  See the
 	<<URLS,URLS>> section below for more information on specifying
Documentation/git-init.txt +15 -2
index 0a4a20e..58cd011 100644
@@ -8,7 +8,9 @@ git-init - Create an empty git repository or reinitialize an existing one
 
 SYNOPSIS
 --------
-'git init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]] [directory]
+'git init' [-q | --quiet] [--bare] [--template=<template_directory>]
+	  [--separate-git-dir|-L <git dir>]
+	  [--shared[=<permissions>]] [directory]
 
 
 DESCRIPTION
@@ -29,7 +31,8 @@ directory is used.
 
 Running 'git init' in an existing repository is safe. It will not
 overwrite things that are already there. The primary reason for
-rerunning 'git init' is to pick up newly added templates.
+rerunning 'git init' is to pick up newly added templates (or to move
+the repository to another place if --separate-git-dir is given).
 
 OPTIONS
 -------
@@ -51,6 +54,16 @@ current working directory.
 Specify the directory from which templates will be used.  (See the "TEMPLATE
 DIRECTORY" section below.)
 
+-L=<git dir>::
+--separate-git-dir=<git dir>::
+
+Instead of initializing the repository where it is supposed to be,
+place a filesytem-agnostic git symbolic link there, pointing to the
+specified git path, and initialize a git repository at the path. The
+result is git repository can be separated from working tree. If this
+is reinitialization, the repository will be moved to the specified
+path.
+
 --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::
 
 Specify that the git repository is to be shared amongst several users.  This
builtin/clone.c +7 -1
index 404f589..097beca 100644
@@ -42,6 +42,7 @@ static int option_local, option_no_hardlinks, option_shared, option_recursive;
 static char *option_template, *option_reference, *option_depth;
 static char *option_origin = NULL;
 static char *option_branch = NULL;
+static const char *real_git_dir;
 static char *option_upload_pack = "git-upload-pack";
 static int option_verbosity;
 static int option_progress;
@@ -80,6 +81,8 @@ static struct option builtin_clone_options[] = {
 		   "path to git-upload-pack on the remote"),
 	OPT_STRING(0, "depth", &option_depth, "depth",
 		    "create a shallow clone of that depth"),
+	OPT_STRING('L', "separate-git-dir", &real_git_dir, "gitdir",
+		   "separate git dir from working tree"),
 
 	OPT_END()
 };
@@ -466,7 +469,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 	if (safe_create_leading_directories_const(git_dir) < 0)
 		die("could not create leading directories of '%s'", git_dir);
-	set_git_dir(real_path(git_dir));
+
+	set_git_dir_init(git_dir, real_git_dir, 0);
+	if (real_git_dir)
+		git_dir = real_git_dir;
 
 	if (0 <= option_verbosity)
 		printf("Cloning into %s%s...\n",
builtin/init-db.c +65 -3

113 lines not on this page · raw message

cache.h +1 -0
index a99fd56..0b99487 100644
@@ -436,6 +436,7 @@ extern void verify_non_filename(const char *prefix, const char *name);
 
 #define INIT_DB_QUIET 0x0001
 
+extern int set_git_dir_init(const char *git_dir, const char *real_git_dir, int);
 extern int init_db(const char *template_dir, unsigned int flags);
 
 #define alloc_nr(x) (((x)+16)*3/2)
t/t0001-init.sh +46 -0

50 lines not on this page · raw message

t/t5601-clone.sh +13 -0
index 987e0c8..c467b67 100755
@@ -192,4 +192,17 @@ test_expect_success 'do not respect url-encoding of non-url path' '
 	git clone x+y xy-regular
 '
 
+test_expect_success 'clone separate gitdir' '
+	rm -rf dst &&
+	git clone --separate-git-dir realgitdir src dst &&
+	echo "gitdir: `pwd`/realgitdir" >expected &&
+	test_cmp expected dst/.git &&
+	test -d realgitdir/refs
+'
+
+test_expect_success 'clone separate gitdir where target already exists' '
+	rm -rf dst &&
+	test_must_fail git clone --separate-git-dir realgitdir src dst
+'
+
 test_done
Signature · 1 line
1.7.4.74.g639db
#2 lore raw
In reply to Nguyễn Thái Ngọc Duy
Quoted 2 lines · Nguyễn Thái Ngọc Duy

- The text mentioning git-init-db is dropped. init-db is deprecated, no need to confuse new users

Shouldn't we add something like this then?

From 86b8daa4bf4c7cd376335570e5f1663c6d6cde01 Mon Sep 17 00:00:00 2001
From: Matthieu Moy <[email protected]>
Date: Sat, 19 Mar 2011 16:54:43 +0100
Subject: [PATCH] shorten git-init-db.txt to only point to git-init.txt

---
 Documentation/git-init-db.txt |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)
Documentation/git-init-db.txt +1 -7
index 2c4c716..b2b959e 100644
@@ -3,13 +3,7 @@ git-init-db(1)
 
 NAME
 ----
-git-init-db - Creates an empty git repository
-
-
-SYNOPSIS
---------
-'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
-
+git-init-db - Deprecated alias for linkgit:git-init[1]
 
 DESCRIPTION
 -----------
Signature · 7 lines
1.7.4.1.293.g8414b



-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#3 lore raw

2011/3/19 Matthieu Moy <[email protected]>:

Quoted 8 lines
Documentation/git-init-db.txt +0 -0
index 2c4c716..b2b959e 100644
@@ -3,13 +3,7 @@ git-init-db(1)
 

 NAME
 ----

Documentation/git-init-db.txt git-init-db(1) · line 6

Quoted 8 lines
Documentation/git-init-db.txt +1 -7
-git-init-db - Creates an empty git repository
-
-
-SYNOPSIS
---------
-'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
-
+git-init-db - Deprecated alias for linkgit:git-init[1]

You should remove DESCRIPTION section too.

Signature · 1 line
Duy