Skip to content

Commit b813ebf

Browse files
committed
Add initial commit after initialization of the repository
After the initialization of a new repository, a user can't use all Git capabilities until the first commit is created. And, since it can't be changed, it is better to create the empty commit. `init-repository` will care about the initial commit and prepare fully-operable repository.
1 parent e17ae99 commit b813ebf

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

docs/commands.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,16 @@ git push --set-upstream --force origin task-123:task-123
172172
usage: git elegant init-repository
173173
```
174174

175-
Creates an empty Git repository (or reinitialize an existing one) and runs its
176-
configuration.
175+
Creates an empty Git repository (or reinitialize an existing one), runs its
176+
configuration, and creates an initial empty commit.
177177

178178
Approximate commands flow is
179179
```bash
180180
==>> git elegant init-repository
181181
git init
182182
git elegant acquire-repository
183+
git commit --allow-empty --file a-message-of-initial-commit
184+
git show
183185
```
184186

185187
# `obtain-work`

libexec/git-elegant-init-repository

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,39 @@ MESSAGE
1515

1616
command-description() {
1717
cat<<MESSAGE
18-
Creates an empty Git repository (or reinitialize an existing one) and runs its
19-
configuration.
18+
Creates an empty Git repository (or reinitialize an existing one), runs its
19+
configuration, and creates an initial empty commit.
2020
2121
Approximate commands flow is
2222
\`\`\`bash
2323
==>> git elegant init-repository
2424
git init
2525
git elegant acquire-repository
26+
git commit --allow-empty --file a-message-of-initial-commit
27+
git show
2628
\`\`\`
2729
MESSAGE
2830
}
2931

3032
default() {
3133
git-verbose init
3234
git elegant acquire-repository
35+
local message="a-message-of-initial-commit"
36+
cat <<MESSAGE > ${message}
37+
Add initial empty commit
38+
39+
This commit is the first commit in this working tree. It does not have
40+
any changes. However, it simplifies further work at least in the
41+
following cases:
42+
- it's possible to create a branch now
43+
- it's possible to manage the second commit if it requires some
44+
polishing after creation
45+
46+
This commit is created automatically by Elegant Git after the
47+
initialization of a new repository.
48+
49+
MESSAGE
50+
git-verbose commit --allow-empty --file ${message}
51+
remove-file ${message}
52+
git-verbose show
3353
}

tests/addons-repo.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ repo-new() {
1212
perform-verbose git config --local user.email "\"[email protected]\""
1313
perform-verbose git config --local user.name "\"Elegant Git\""
1414
perform-verbose git config --local core.editor "\"vi\""
15+
perform-verbose git config --local core.pager cat
1516
perform-verbose touch ${FILE_TO_MODIFY}
1617
perform-verbose git add .
1718
perform-verbose git commit -m "\"Add ${FILE_TO_MODIFY}\""
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
#!/usr/bin/env bats
22

33
load addons-common
4-
load addons-read
54
load addons-fake
5+
current=$(pwd)
6+
repository=${current}/new-repository
67

78
setup() {
8-
fake-pass "git init"
99
fake-pass "git elegant acquire-repository"
10+
perform-verbose "mkdir -p ${repository}"
11+
perform-verbose "cd ${repository}"
12+
perform-verbose "git config --global user.email [email protected]"
13+
perform-verbose "git config --global user.name YourName"
14+
perform-verbose "git config --global core.pager cat"
1015
}
1116

1217
teardown() {
18+
perform-verbose "cd ${current}"
19+
perform-verbose "rm -rf ${repository}"
20+
perform-verbose "git config --global --unset user.email"
21+
perform-verbose "git config --global --unset user.name"
22+
perform-verbose "git config --global --unset core.pager"
1323
fake-clean
1424
}
1525

16-
@test "'init-repository': command is available" {
17-
check git-elegant init-repository
18-
[ "$status" -eq 0 ]
26+
@test "'init-repository': creates a new repository with initial commit" {
27+
check git-elegant init-repository
28+
[[ ${status} -eq 0 ]]
29+
[[ ${lines[@]} =~ "git init" ]]
30+
[[ ${lines[@]} =~ "git commit --allow-empty" ]]
31+
[[ ${lines[@]} =~ "git show" ]]
32+
[[ ${lines[@]} =~ "Add initial empty commit" ]]
1933
}

0 commit comments

Comments
 (0)