init-db: support --import to add all files and commit right after init
PATCH 1/1 init-db: support --import to add all files and commit right after init
This is equivalent to "git init;git add .;git commit -q -m blah". I find myself doing that too many times, hence this shortcut.
In future, --fast-import support would also be nice if the import directory has a lot of files.
---
I'm not really sure about document format as I failed to install xmlto on my machine. Html output looked fine though.
Documentation/git-init.txt | 16 +++++++++++++- builtin-init-db.c | 49 ++++++++++++++++++++++++++++++++++++++++--- t/t0001-init.sh | 32 ++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 5 deletions(-)
Documentation/git-init.txt +15 -1
@@ -8,7 +8,8 @@ git-init - Create an empty git repository or reinitialize an existing one SYNOPSIS -------- -'git init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]] +'git init' [-q | --quiet] [--bare] [--template=<template_directory>] + [--shared[=<permissions>]] [-m <message> | --import=<message>] OPTIONS
@@ -68,6 +69,19 @@ By default, the configuration flag receive.denyNonFastForwards is enabled in shared repositories, so that you cannot force a non fast-forwarding push into it. +-m <message>:: +--import=<message>:: + +Commit everything to the newly initialized repository. This is equivalent to: + +---------------- +$ git init +$ git add . +$ git commit -q -m <message> +---------------- + +This option does not work with `--bare` nor already initialized repository. + --
builtin-init-db.c +45 -4
96 lines not on this page · raw message
t/t0001-init.sh +32 -0
@@ -199,4 +199,36 @@ test_expect_success 'init honors global core.sharedRepository' ' x`git config -f shared-honor-global/.git/config core.sharedRepository` ' +test_expect_success 'init --import with --bare' ' + ( + unset GIT_DIR GIT_WORK_TREE GIT_CONFIG + mkdir init-import-bare.git && + cd init-import-bare.git && + ! git init --bare --import test + ) + +' + +test_expect_success 'init --import' ' + ( + test_tick + unset GIT_DIR GIT_WORK_TREE GIT_CONFIG + mkdir init-import && + cd init-import && + touch foo bar && + git init --import test && + test "$(git rev-parse HEAD)" = 758aa5a579e42200a6fd4e4964c7e1dc1875d67d + ) +' + +test_expect_success 'reinit --import' ' + ( + test_tick + unset GIT_DIR GIT_WORK_TREE GIT_CONFIG + cd init-import && + ! git init --import testagain && + test "$(git rev-parse HEAD)" = 758aa5a579e42200a6fd4e4964c7e1dc1875d67d + ) +' + test_done
Signature · 1 line
1.6.1.446.gc7851
Quoted 2 lines · Nguy???n Th??i Ng???c Duy
This is equivalent to "git init;git add .;git commit -q -m blah". I find myself doing that too many times, hence this shortcut.
Why not:
git config --global alias.init-import '!git init && git add . && git commit -q'
?
Signature · 1 line
Shawn.
Quoted 7 lines · Shawn O. Pearce
Quoted 2 lines · Nguy???n Th??i Ng???c Duy
This is equivalent to "git init;git add .;git commit -q -m blah". I find myself doing that too many times, hence this shortcut.
Why not:
git config --global alias.init-import '!git init && git add . && git commit -q'
1. less setup on new machine
2. fast-import support (not yet though)
Signature · 1 line
Duy
Quoted 2 lines · Nguyễn Thái Ngọc Duy
This is equivalent to "git init;git add .;git commit -q -m blah". I find myself doing that too many times, hence this shortcut.
I think I would find this handy. Shawn suggested an alias, but I think this is perhaps "universal enough" to merit an actual command-line option.
Documentation/git-init.txt By default, the configuration flag receive.denyNonFastForwards is enabled · line 75
Quoted 4 lines
+-m <message>:: +--import=<message>::Documentation/git-init.txt +2
-0+ +Commit everything to the newly initialized repository. This is equivalent to:
Maybe this is being too lazy, but I think it would be useful to allow just "--import" without a message to default to "Initial commit", "initial import from basename $PWD", or something like that.
builtin-init-db.c int cmd_init_db(int argc, const char **argv, const char *prefix) · line 425
Quoted 7 lines
builtin-init-db.c +7
-0+else if (!strcmp (arg,"--import" ) || !strcmp (arg,"-m" )) { +if (i+1 >= argc) +die ("--import requires an import message" ); + import_message = argv[2 ]; + i++; + argv++; + }
I seem to recall that we were phasing out "--long-option <arg>" at some point, and that all long-options should use "--long-option=". But maybe I am mis-remembering.
-Peff
2009/3/25 Jeff King <[email protected]>:
Quoted 8 lines
Documentation/git-init.txt By default, the configuration flag receive.denyNonFastForwards is enabled · line 75
Quoted 4 lines
+-m <message>:: +--import=<message>::Documentation/git-init.txt +2
-0+ +Commit everything to the newly initialized repository. This is equivalent to:Maybe this is being too lazy, but I think it would be useful to allow just "--import" without a message to default to "Initial commit", "initial import from
basename $PWD", or something like that.
I tend to do "commit -q -m i", not a big deal for two more keystrokes. My initial version allowed "git init /path/to/workdir" too so it might be ambiguous for optional message. So all vote for "Initial commit"? Dynamic message seems overkill because most of the cases, this is a throw away repository.
Quoted 11 lines
Quoted 7 lines
+ else if (!strcmp(arg, "--import") || !strcmp(arg, "-m")) {
+ if (i+1 >= argc)
+die("--import requires an import message");
+import_message= argv[2];
+ i++;
+ argv++;
+ }I seem to recall that we were phasing out "--long-option <arg>" at some point, and that all long-options should use "--long-option=". But maybe I am mis-remembering.
I did not know too. Any reference?
Signature · 1 line
Duy
Quoted 5 lines · Nguyen Thai Ngoc Duy
I tend to do "commit -q -m i", not a big deal for two more keystrokes. My initial version allowed "git init /path/to/workdir" too so it might be ambiguous for optional message. So all vote for "Initial commit"? Dynamic message seems overkill because most of the cases, this is a throw away repository.
Initial commit is fine with me. I plan to use this mostly for throw-away repositories. I was thinking it might be useful for this:
tar xzf package-0.1.tar.gz cd package-0.1 git init --import
so that later you remember it came from package-0.1 (when you are looking at package 0.2). OTOH, if we take the information from the directory, then the fact that it came from 0.1 is by definition already in the directory name. So it is pretty pointless unless you later rename the directory to just "package".
Quoted 5 lines
Quoted 3 lines
I seem to recall that we were phasing out "--long-option <arg>" at some point, and that all long-options should use "--long-option=". But maybe I am mis-remembering.
I did not know too. Any reference?
I was, in fact, mis-remembering. The problem is not about long versus short options, but rather about options which have an optional value. See "Separating argument from the option" in "git help cli".
However, what we are discussing above _is_ making it an optional value, in which case "--import <arg>" would have no value for "--import".
-Peff
Hi,
Quoted 7 lines · Nguyễn Thái Ngọc Duy
This is equivalent to "git init;git add .;git commit -q -m blah". I find myself doing that too many times, hence this shortcut.
In future, --fast-import support would also be nice if the import directory has a lot of files.
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>
I wanted to have this for a _long_ time!
But could you please say "init" in the subject instead of "init-db"? The latter is just a historical wart we have to carry around.
Thanks,
Dscho
2009/3/25 Johannes Schindelin <[email protected]>:
Quoted 2 lines
But could you please say "init" in the subject instead of "init-db"? The latter is just a historical wart we have to carry around.
OK. No problem.
Signature · 1 line
Duy
Quoted 3 lines · Jeff King
I seem to recall that we were phasing out "--long-option <arg>" at some point, and that all long-options should use "--long-option=". But maybe I am mis-remembering.
Surely it should support both where possible, since both are standard syntaxes for passing args to "--"-style long options (so users expect both to work).
-Miles
Signature · 1 line
Occam's razor split hairs so well, I bought the whole argument!
Quoted 8 lines · Miles Bader
Quoted 3 lines · Jeff King
I seem to recall that we were phasing out "--long-option <arg>" at some point, and that all long-options should use "--long-option=". But maybe I am mis-remembering.
Surely it should support both where possible, since both are standard syntaxes for passing args to "--"-style long options (so users expect both to work).
Yes. See later in the thread where I correctly remember the issue.
-Peff