-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit_init_project
executable file
·46 lines (36 loc) · 1.3 KB
/
git_init_project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
# Prepopulates a git repo out of the rendered template with an initial commit+tag
create_git_repository() {
# if [ $# -lt 2 ]; then
# echo "Usage: create_git_repository USER_NAME USER_EMAIL"
# echo $?
# exit 1
# fi
# AUTHOR_NAME=$1
# AUTHOR_EMAIL=$2
# If a git repo is already in place
if [[ -d ".git/" ]];
then
echo "Repo already exists. Exiting..."
exit 0 # No action, exit early
fi
echo "Creating a git repo..."
# First create empty git repo
git init --initial-branch main
# Temporarily set commiter name.
# Nicely solves problem of "missing git user" in CI by making all
# template instantiation use a set user name/email combo
git config --get user.name > /dev/null || git config --local user.name "${AUTHOR_NAME}"
git config --get user.email > /dev/null || git config --local user.email "${AUTHOR_EMAIL}"
# Commit
git add --all
git commit \
--message "Initial commit from 'copier' template"
git tag v0.1.0 \
--annotate \
--message "First releasable artefact, from template"
# Reset the user config after committing if fallback values were used
git config --unset user.name || true
git config --unset user.email || true
}
create_git_repository