Test commit
[cogito/jonas.git] / cg-init
blob653f759018c1311f628a78477d4407e59101faf9
1 #!/usr/bin/env bash
3 # Initialize new repository
4 # Copyright (c) Petr Baudis, 2005
6 # `cg-init` called in a non-empty directory will automatically add its contents
7 # in the initial commit. (Please note that certain default ignore rules are
8 # applied during this operation - see `cg-status` for detailed description.
9 # If any files were not added due to this, cg-init will advise you what to do.)
11 # This command is intended for creating repositories for work on new projects.
12 # If you want to clone an existing project, see `cg-clone`. If you want to
13 # set up a public repository not for direct work but only for pushing/fetching,
14 # see `cg-admin-setuprepo`. It is also possible to import repositories from
15 # other SCMs to GIT, see `git-cvsimport(1)`, `git-svnimport(1)` and
16 # `git-archimport(1)`.
18 # OPTIONS
19 # -------
20 # -e EXCLUDEPATTERN:: Ignore files matching EXCLUDEPATTERN
21 # Ignore files matching this pattern when importing files for the
22 # initial commit. Note that if you are importing any .gitignore
23 # files, they will be considered as well (see `cg-status` for
24 # details on the files ignoring concept). If you want to make
25 # an even more custom choice of files to be imported, use the -I
26 # parameter and add and perform the initial commit manually.
28 # -I:: No initial commit
29 # Do not perform the initial commit. You can perform the initial commit
30 # manually later, just call `cg-commit`.
32 # -m MESSAGE:: Specify initial commit message
33 # Specify the commit message for the initial commit. See `cg-commit`
34 # documentation for details.
36 # -N:: Only update the cache
37 # Only update the cache: do not copy the data into the object database.
38 # This is for special purposes when you might not actually _have_ any
39 # object database. This option is normally not interesting.
41 # Testsuite: Almost complete (t9000-init, missing -N test)
43 USAGE="cg-init [-I] [-N] [-e EXCLUDEPATTERN]... [-m MESSAGE]..."
44 _git_repo_unneeded=1
46 . "${COGITO_LIB}"cg-Xlib || exit 1
48 excludes=()
49 no_initial_commit=
50 commitargs=()
51 infoonly=
52 while optparse; do
53 if optparse -e=; then
54 excludes[${#excludes[@]}]="$OPTARG"
55 elif optparse -I; then
56 no_initial_commit=1
57 elif optparse -m=; then
58 commitargs[${#commitargs[@]}]="-m"
59 commitargs[${#commitargs[@]}]="$OPTARG"
60 elif optparse -N; then
61 infoonly=-N
62 else
63 optfail
65 done
66 [ "${commitargs[*]}" ] || commitargs=(-m "Initial commit")
67 if tty -s; then
68 commitargs[${#commitargs[@]}]="-e"
71 [ -e "$_git" ] && die "$_git already exists"
73 cleanup_trap "rm -rf $_git"
75 git-init-db
77 git-read-tree # Seed the dircache
78 if ! [ "$no_initial_commit" ]; then
79 [ "$(ls)" ] && list_untracked_files exclude nosquashdirs "${excludes[@]}" | xargs -0 cg-add ${infoonly}
80 cg-commit -C "${commitargs[@]}" ${infoonly} || die "Initial commit aborted"
83 if [ "$(cg-status -nwx)" ]; then
84 echo "cg-init: Note that some files were not added due to the default ignore rules." >&2
85 echo "cg-init: You can list them by invoking 'cg-status -x'." >&2
88 exit 0