GitLab system status is available here and here

Commit 5dda9035 authored by Anthony Umemoto's avatar Anthony Umemoto
Browse files

v1.0.1

parent 2c1a31a6
# GITMANG
# GITMANG v1.0.1
Anthony Umemoto 2022, with debugging assistance from Omar Ahmadyar.
gitmang can be downloaded off the gitLab web interface, or the gitmang master branch can be pulled using:
`$ git clone git@git.ucsc.edu:atumemot/gitmang gitmang`
gitmang is an ongoing project, regularly check this repository for bug fixes and iprovements. Refer to UPDATE.md for changes between versions.
## DESCRIPTION
A shell script for automated git repository management in the command line environment. It commits specified files at a regular interval. The default file types that will always be included are *.c and *.h. Each commit will have the comment `autosaving progress <timestamp>`.
A shell script for automated git repository management in the command line environment. It commits specified files at a regular interval. Each commit will have the comment `autosaving progress <timestamp>`.
## USAGE
`$ ./gitmang.sh [-hB] [-R dir] [-d dir] [-f freq] [-r reps] [file1 file2 ...]`
`$ ./gitmang.sh [-hB] [-RdD dir] [-f freq] [-r reps] [file1 file2 ...]`
git must be installed, and the gitmang.sh script should be in the main directory. To give gitmang.sh executing permissions use:
git must be installed, and gitmang should be run in a UNIX or git bash terminal. gitmang is currently untested in other terminals such as the Windows command prompt, and the macOS terminal. To give executing permissions use:
`$ chmod +x gitmang.sh`
......@@ -18,7 +24,9 @@ gitmang requires that a terminal window is dedicated to running it. Open a new t
`$ ssh <username>@localhost -p <port>`
When quitting the program, use the 'q' input option to quit properly. Always remember to quit properly before turning off your machine. If gitmang is unexpectedly ended while it is performing a commit, the repository directory may become corrupt. If this happens, delete the directory with:
Or open a new git bash window in your gitmang local repository.
When quitting the program, use the 'q' input option to quit properly. Always remember to quit properly before turning off your machine. If gitmang is unexpectedly ended while it is performing a commit, the local repository may become corrupt. If this happens, delete the repository directory with:
`$ rm -rf <dir>`
......@@ -34,23 +42,27 @@ If the correct URL is returned, then the repair should work.
## OPTIONS
`-d dir` The file path to th repository being managed, this must be specified.
`-d dir` The file path, from the current working directory, to the repository being managed.
`-D dir` The file path, from the main directory, to the repository being managed (recommended for UNIX only).
`-f freq` The time interval in minutes between each commit (default: 5).
`-r reps` The number of commits to be made before ending (defualt: 100).
`-R dir` Repairs the corrupted repository dir, saving un-committed files.
`-R dir` Repairs the corrupted repository dir (path from working directory), saving un-committed files.
`-B` Keeps gm_repair_backup directory after repository repair. This can be used as a backup in case [-R dir] fails.
`-B` Keeps gm_repair_backup directory after repository repair. This can be used as a backup in case [-R dir] fails. gm_repair_backup is placed in the same directory the local repository is a child of.
`-h` Display program usage and synopsis.
`file1 file2 ...` File names that will be added to the commit list.
## PROGRAM INPUT
`q` Quits the program.
`d dir` Changes the git repo being managed. The file path should be from the main directory.
`d dir` Changes the git repo being managed. The file path should be from the current working directory.
`f freq` Changes the interval between each commit.
......@@ -66,5 +78,6 @@ Prints to stdout:
## ERRORS
+ gitmang currently has no error handling in any case where a git command fails.
+ gitmang currently lacks sufficient error handling.
+ All variables are prepended with `gm_` to prevent overriding other global variables, but this is still possible since most of the script is not contained within a function.
+ git commands do not behave properly when inclosed in a function, script is bloated as a result.
\ No newline at end of file
# GITMANG UPDATE LOG
Most recent version is listed first.
### v1.0.1 March 18, 2022 7:30PM PST
+ Improved directory navigation of the [-dDR dir] commands. They now have more predictable behavior, and are more flexible with various directory structures.
+ Improved error handling for invalid directory inputs.
+ Revised documentation.
+ Added this update log.
\ No newline at end of file
......@@ -5,48 +5,33 @@ function gm_usage {
echo ""
echo "SYNOPSIS"
echo " A shell script that commits specified files at a regular interval."
echo " The default file types that will always be included are *.c and *.h."
echo " Each commit will have the comment 'autosaving progress <timestamp>'."
echo ""
echo "USAGE"
echo " $ ./gitmang.sh [-HB] [-R dir] [-d dir] [-f freq] [-r reps] [file1 file2 ...]"
echo ""
echo " git must be installed, and the gitmang.sh script should be"
echo " in the main directory. gitmang requires that a terminal window"
echo " is dedicated to running it. Open a new terminal with:"
echo " $ ssh <username>@localhost -p <port>"
echo " When quitting the program, use the 'q' input option to quit properly."
echo " Always remember to quit properly before turning off your machine."
echo " If gitmang is unexpected ended while it is performing a commit,"
echo " the repository directory may become corrupt."
echo " If this happens, delete the directory with:"
echo " $ rm -rf <dir>"
echo " and re-clone it with:"
echo " $ git clone <repo> <dir>"
echo " Alternatively, use the [-R dir] command to repair the local repository"
echo " to save un-committed work. However, this command only works if the remote"
echo " repository URL is uncorrupted. To test if it is, use:"
echo " $ git config --get remote.origin.url"
echo " If the correct URL is returned, then the repair should work."
echo " $ ./gitmang.sh [-hB] [-RdD dir] [-f freq] [-r reps] [file1 file2 ...]"
echo ""
echo "OPTIONS"
echo " -d dir The file path to the repo being managed, this must be specified."
echo " -f freq The time interval in minutes between each commit (default: 5)."
echo " -r reps The number of commits to be made before ending (default: 100)."
echo " -R dir Repairs the corrupted repository dir, saving un-committed files."
echo " -B Keeps gm_repair_backup directory after repository repair."
echo " This can be used as a backup in case [-R dir] fails."
echo " -h Display program synopsis and usage."
echo " -d dir The file path, from the current working directory, to the repo being managed."
echo " -D dir The file path, from the main directory, to the repository being managed."
echo " -f freq The time interval in minutes between each commit (default: 5)."
echo " -r reps The number of commits to be made before ending (default: 100)."
echo " -R dir Repairs the corrupted repository dir, saving un-committed files."
echo " Path is from working directory."
echo " -B Keeps gm_repair_backup directory after repository repair."
echo " This can be used as a backup in case [-R dir] fails."
echo " -h Display program synopsis and usage."
echo " file1 ... File names that will be added to the commit list."
echo ""
echo "PROGRAM INPUT"
echo " q Quits the program."
echo " d dir Changes the git repo being managed."
echo " The file path should be from the main directory."
echo " The file path should be from the current working directory."
echo " f freq Changes the interval between each commit."
echo " a file Adds a single file to the commit list."
echo " To add another file, [a file] will need to be used again."
echo " h Display program input options."
echo ""
echo "For more usage information, view the README."
echo ""
echo "OUTPUT"
echo " Prints to stdout:"
echo " <reps> commit(s) completed over <total time> minute(s)"
......@@ -60,7 +45,7 @@ function gm_options {
echo "INPUT OPTIONS"
echo " q Quits the program."
echo " d dir Changes the git repo being managed."
echo " The file path should be from the main directory."
echo " The file path should be from the current working directory."
echo " f freq Changes the interval between each commit."
echo " a file Add a single file to the commit list."
echo " To add aother file, [a file] will need to be used again."
......@@ -73,23 +58,32 @@ function gm_options {
# default options
gm_dir=""
gm_main=0
gm_freq=5
gm_reps=100
gm_repair=0
gm_backup=0
gm_files=( *.c *.h )
gm_files=()
# process command line arguments
while getopts d:f:r:R:Bh opt; do
while getopts d:D:f:r:R:Bh opt; do
case "${opt}" in
d) gm_dir=${OPTARG};;
D)
gm_dir=${OPTARG}
gm_main=1;;
f)
if (( ${OPTARG} > 0 )); then
gm_freq=${OPTARG}
else
echo "interval must be greater than 0, will remain 5 mins"
echo "Interval must be greater than 0, will remain 5 mins."
fi;;
r)
if (( ${OPTARG} > 0 )); then
gm_reps=${OPTARG}
else
echo "Number of commits must be greater than 0, will remain 100."
fi;;
r) gm_reps=${OPTARG};;
R)
gm_dir=${OPTARG}
gm_repair=1;;
......@@ -100,42 +94,61 @@ while getopts d:f:r:R:Bh opt; do
esac
done
# test for invalid input
# test for no directory input
if [[ $gm_dir == "" ]]; then
echo "Repo directory must be specified, exitting program."
exit
fi
# repair repo
if (( $gm_repair == 1 )); then
# get gitmang dir for error testing
gm_gmdir=$(pwd)
# try to move into dir
cd $gm_dir
# test if gm_dir is a valid path
if [[ $gm_gmdir == $(pwd) ]]; then
echo "$gm_dir is an invalid directory, exitting program."
exit
fi
# get remote repo url
gm_url=$(git config --get remote.origin.url)
# test if gm_dir is a valid repo
if [[ $gm_url == "" ]]; then
echo "$gm_dir is not a repository, exitting program."
exit
fi
gm_repo=$(basename $(pwd))
cd ../
# make temp dir
mkdir gm_repair_backup
# copy files into temp dir
cp -r $gm_dir/* gm_repair_backup
cp -r $gm_repo/* gm_repair_backup
# get remote repo url
cd $gm_dir
gm_url=$(git config --get remote.origin.url)
cd
echo "Repair backup created."
# delete dir and re clone
rm -rf $gm_dir
git clone $gm_url $gm_dir
rm -rf $gm_repo
git clone $gm_url $gm_repo
# replace files
rm -rf $gm_dir/*
cp -r gm_repair_backup/* $gm_dir
rm -rf $gm_repo/*
cp -r gm_repair_backup/* $gm_repo
# delete temp dir
if (( $gm_backup == 0 )); then
echo "deleting backup"
echo "Deleting repair backup."
rm -rf gm_repair_backup
fi
echo "repository repair complete"
echo "Repository repair complete."
exit
fi
......@@ -145,8 +158,23 @@ shift $(($OPTIND - 1))
gm_files+=( $@ )
# moves into specified directory
if (( gm_main == 1 )); then
cd
fi
cd $gm_dir
# test if gm_dir is a valid path
if [[ $(basename $gm_dir) != $(basename $(pwd)) ]]; then
echo "Failed to move into $gm_dir, exitting program."
exit
fi
# test if gm_dir is a valid repo
if [[ $(git config --get remote.origin.url) == "" ]]; then
echo "$gm_dir is not a repository, exitting program."
exit
fi
gm_sreps=0 # counts how many reps were completed while program was running
gm_stime=0 # counts how many minutes have passed with each commit
gm_cmd="" # stores command if one is used during program runtime
......@@ -172,16 +200,30 @@ while (( $gm_reps > 0 )); do
# program input
if (( $gm_reps > 0 )); then
read -t $((gm_freq*60)) -p "Input command, use H for options: " gm_cmd gm_arg
read -t $((gm_freq*60)) -p "Input command, use h for options: " gm_cmd gm_arg
case "$gm_cmd" in
q) gm_reps=1;;
d)
if [[ gm_arg == ""]]; then
if [[ gm_arg == "" ]]; then
echo "Repo directory must be specified."
break
else
cd
# check for invalid directory
gm_tmpdir=$(pwd)
cd $gm_arg
# test if gm_dir is a valid path
if [[ $gm_tmpdir == $(pwd) ]]; then
echo "Failed to move into $gm_arg, remaining in $gm_dir."
break
fi
# test if gm_dir is a valid repo
if [[ $(git config --get remote.origin.url) == "" ]]; then
echo "$gm_arg is not a repository, remaining in $gm_dir."
break
fi
gm_dir=$gm_arg
echo "Switched directory to $gm_arg."
fi;;
f)
......@@ -200,4 +242,4 @@ while (( $gm_reps > 0 )); do
done
# program output
echo "$gm_sreps commit(s) completed over $gm_stime minute(s)."
echo "$gm_sreps commit(s) completed over $gm_stime minute(s)."
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment