Skip to contentSkip to conversation

init: support --import to add all files and commit right after init

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

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 init: 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.

---
Hopefully I don't make any mistake this time. -m will not take any argument for two reasons:

- optional argument for short options does not appear anywhere in git AFAIK. let's not make parse-opt migration more difficult with -mfoo or -m=foo
- you want it short, so make it short :) if you want your own message, you probably won't mind typing a few more: --import=blah

 Documentation/git-init.txt |   17 ++++++++++++++++-
 builtin-init-db.c          |   44 ++++++++++++++++++++++++++++++++++++++++----
 t/t0001-init.sh            |   44 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 5 deletions(-)
Documentation/git-init.txt +16 -1
index 71749c0..52bc34a 100644
@@ -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 | --import[=<message>]]
 
 
 OPTIONS
@@ -68,6 +69,20 @@ 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::
+--import[=<message>]::
+
+Commit everything to the newly initialized repository. This is equivalent to:
+
+----------------
+$ git init
+$ git add .
+$ git commit -q -m <message>
+----------------
+
+If `-m` is used or no message is given to `--import`, "Initial commit" will be used.
+This option does not work with `--bare` nor already initialized repository.
+
 --
 
 
builtin-init-db.c +40 -4

91 lines not on this page · raw message

t/t0001-init.sh +44 -0

48 lines not on this page · raw message

Signature · 1 line
1.6.1.446.gc7851
#1 lore raw
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.

This version looks OK to me, but I have a few comments:

Quoted 5 lines

Hopefully I don't make any mistake this time. -m will not take any argument for two reasons:

- optional argument for short options does not appear anywhere in git AFAIK. let's not make parse-opt migration more difficult with -mfoo or -m=foo

shortlog's -w has optional arguments (and is the option that spawned the discussion that led to Pierre writing the gitcli(7) text, IIRC). So parse-options does handle it, but you _cannot_ say "-m foo" anymore.

Quoted 2 lines
+-m::
+--import[=<message>]::

Nit: -m made sense when it specified a message. But now that it doesn't take a message, maybe "-i" would be more appropriate?

Quoted 1 line

+If -m is used or no message is given to --import, "Initial commit" will be used.

Style nit: long line.

-Peff