File: make_git_repo.bash

package info (click to toggle)
cloc 1.86-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,360 kB
  • sloc: perl: 25,138; cpp: 1,219; ansic: 320; asm: 267; makefile: 237; sh: 181; ruby: 111; java: 81; python: 54; cs: 46; lisp: 45; haskell: 35; f90: 35; cobol: 35; objc: 25; php: 22; pascal: 18; javascript: 15; fortran: 9; xml: 3; tcl: 2
file content (122 lines) | stat: -rwxr-xr-x 2,913 bytes parent folder | download | duplicates (5)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# 2018-04-06 Al Danial <al.danial@gmail.com>

# Create in the current directory a git repository
# called 'GitTestRepo' and populate it with a few
# files over several commits.  The repo is used to
# exercise some of cloc's git features.

G=`which git`
if test ! $G ; then 
    echo "git is unavailable, exit."
    exit
fi

function git_init_config {                                  # {{{
    reponame=$1
    git init --quiet "${reponame}"
    cd "${reponame}"
    # explicitly don't use --global; settings for this repo only
    git config user.email "cloc.tester@github.com"
    git config user.name  "Cloc Tester"
}
# 1}}}
function create_main_c {                                    # {{{
fname=$1
N=$2
cat <<EO_001 > "${fname}"
/*
 *               gcc hello.c -o hello
 */
main (int argc, char *argv[])
{
  printf("Hello. $N\n");
}
EO_001
}
# 1}}}
function create_py {                                        # {{{
fname=$1
cat <<EO_002 > "${fname}"
#!/usr/bin/env python

print('hi')
EO_002
}
# 1}}}
function mod_py_A {                                         # {{{
fname=$1
cat <<EO_003 > "${fname}"
#!/usr/bin/env python
print('hi')
print('hello')
EO_003
}
# 1}}}
function mod_py_B {                                         # {{{
fname=$1
cat <<EO_004 > "${fname}"
#!/usr/bin/env python

# five
for i in range(5):
    print('yo')  # print

EO_004
}
# 1}}}
function git_add_commit {                                   # {{{
    fname=$1
    comment=$2
    taglabel=$3
    git add "${fname}"
    git commit --quiet -m "${comment}" "${fname}"
    git tag "${taglabel}"
}
# 1}}}
function git_rm_commit {                                    # {{{
    fname=$1
    comment=$2
    taglabel=$3
    git rm --quiet "${fname}"
    git commit --quiet -m "${comment}" "${fname}"
    git tag "${taglabel}"
}
# 1}}}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#                                    main                                 #

git_init_config GitTestRepo # side effect: cd into GitTestRepo

F1=main.c
F2='date;ls ?.c'
F3='$PWD.c'
F4="weird'name.c"
F5='ls -l .c'
F6='Weird"Name.c'

create_main_c  $F1  1
create_main_c "$F2" 2
create_main_c  $F3  3
create_main_c  $F4  4
create_main_c "$F5" 5
create_main_c  $F6  6
git_add_commit  $F1  "added $F1"  "Tag1"
    git add 'date;ls ?.c'
    git commit --quiet -m "${comment}" 'date;ls ?.c'
    git tag "Tag2"
git_add_commit  $F3  "added $F3"  "Tag3"
git_add_commit  $F4  "added $F4"  "Tag4"
    git add 'ls -l .c'
    git commit --quiet -m "${comment}" 'ls -l .c'
    git tag "Tag5"
git_add_commit  $F6  "added $F6"  "Tag6"

create_py      hello.py
git_add_commit hello.py "add hello.py"              "T2"
mod_py_A       hello.py
git_add_commit hello.py "mod A"                     "T3"
mod_py_B       hello.py
git_add_commit hello.py "mod B"                     "T4"
git_rm_commit  main.c   "using Python instead of C" "T5"