GitLab system status is available here and here

Commit 3bb467e7 authored by Anthony Umemoto's avatar Anthony Umemoto
Browse files

v1.2.0

parent 07d737a0
# GITMANG v1.0.2
# GITMANG v1.2.0
gitmang can be downloaded off the gitLab web interface, or the gitmang master branch can be pulled using:
......@@ -6,13 +6,21 @@ gitmang can be downloaded off the gitLab web interface, or the gitmang master br
gitmang is an ongoing project, regularly check this repository for bug fixes and improvements. Refer to UPDATE.md for changes between versions.
A second branch called beta is used for testing upcoming versions. It is not recommended to use the gitmang from this branch, as it may be unstable and incomplete.
## DESCRIPTION
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>`.
## PROGRAM FILES
+ gitmang.sh: The shell script for automating git repository management.
+ UPDATE.md: Lists each version of gitmang, and what changes were made.
+ README.md: Explains how to use gitmang.
## USAGE
`$ ./gitmang.sh [-hB] [-RdD dir] [-f freq] [-r reps] [file1 file2 ...]`
`$ ./gitmang.sh [-vsBh] [-dDR dir] [-b branch] [-f freq] [-r reps] [file1 file2 ...]`
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:
......@@ -24,7 +32,7 @@ gitmang requires that a terminal window is dedicated to running it. Open a new t
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:
When quitting the program, use the 'q' runtime 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>`
......@@ -40,33 +48,49 @@ If the correct URL is returned, then the repair should work.
## OPTIONS
`-v` Display verbose program output.
`-s` Silence commit and push summaries.
`-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).
`-b branch` Begins gitmang in branch. Creates branch if it does not exist (default: master).
`-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 (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. gm_repair_backup is placed in the same directory the local repository is a child of.
`-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 repaired repository is a child of.
`-h` Display program usage and synopsis.
`file1 file2 ...` File names that will be added to the commit list.
`file1 file2 ...` File names that will be added to the commit list.
`-h` Display program usage and synopsis.
## PROGRAM INPUT
## RUNTIME OPTIONS
`q` Quits the program.
`v` Toggle verbose program output.
`s` Toggle commit and push summaries.
`d dir` Changes the git repo being managed. The file path should be from the current working directory.
`b branch` Moves to branch. Creates branch if it does not exist. If no branch is specified, then the branch list will be printed.
`f freq` Changes the interval between each commit.
`a file` Adds a single file to the commit list. To add another file, [a file] will need to be used again.
`h` Display program input options.
`r file` Removes a single file from the commit list.
`l` Displays the commit list.
`h` Display program runtime options.
## OUTPUT
......@@ -80,7 +104,10 @@ If you encounter a bug, please report it using this form: https://docs.google.co
### ERRORS
### UNEXPECTED BEHAVIORS
### UNEXPECTED/UNWANTED BEHAVIORS
+ A commit is counted even if nothing is pushed. This is seen in the verbose output, and the program output.
+ Usage and synopsis may not fit in terminal windows completely. This is particularly a problem for terminals that cannot scroll up.
### ARCHITECTURE
......
......@@ -2,6 +2,16 @@
Most recent version is listed first.
### v1.2.0 March 22, 2022 3:30PM PDT
+ "Input Options" are now referred to as "Runtime Options" to prevent confusion with "Command Line Options".
+ Other small documentation revisions.
+ Added branch switching with the [-b branch] option. The same can be done with the [b brach] runtime option to switch branches during runtime.
+ Verbose output can now be enabled with the [-v] option. Using the [v] runtime option toggles verbose output during runtime.
+ Commit and push summaries can now be silenced with [-s] option. Using the [s] runtime option toggles the summaries during runtime.
+ Added the [l] runtime option, which displays what files are currently in the commit list.
+ Added the [r file] runtime option, which removes the file name from the commit list.
### v1.0.2 March 18, 2022 7:30PM PDT
+ The total time is now correctly output when the program ends.
......
#!/bin/bash
# USAGE MESSAGES ---------------------------------------------------------
function gm_options {
echo "RUNTIME OPTIONS"
echo " q Quits the program."
echo " v Toggle verbose program output."
echo " s Toggle commit and push summaries."
echo " d dir Changes the git repository being managed."
echo " The file path should be from the current working directory."
echo " b branch Moves to branch. Creates branch if it does not exist."
echo " If no branch is specified, then the branch list will be printed."
echo " f freq Changes the interval between each commit."
echo " a file Add a single file to the commit list."
echo " r file Removes a single file from the commit list."
echo " l Displays the commit list."
echo " h Display program runtime options."
}
function gm_usage {
echo "GITMANG.SH HELP:"
echo "GITMANG.SH HELP: For more usage information, view the README."
echo ""
echo "SYNOPSIS"
echo " A shell script that commits specified files at a regular interval."
echo ""
echo "USAGE"
echo " $ ./gitmang.sh [-hB] [-RdD dir] [-f freq] [-r reps] [file1 file2 ...]"
echo " $ ./gitmang.sh [-vsBh] [-dDR dir] [-b branch] [-f freq] [-r reps] [file1 file2 ...]"
echo ""
echo "OPTIONS"
echo " -d dir The file path, from the current working directory, to the repo being managed."
echo " -v Display verbose program output."
echo " -s Silence commit and push summaries."
echo " -d dir The file path, from the current working directory, to the repository being managed."
echo " -D dir The file path, from the main directory, to the repository being managed."
echo " -b branch Begins gitmang in branch. Creates branch if it does not exist (default: master)."
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 " -h Display program synopsis and usage."
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 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."
gm_options # runtime options
echo ""
echo "OUTPUT"
echo " Prints to stdout: <reps> commit(s) completed over <total time> minute(s)"
......@@ -39,22 +51,15 @@ function gm_usage {
echo " Anthony Umemoto 2022, with debugging assistance from Omar Ahmadyar."
}
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 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."
echo " h Display program input options."
echo ""
}
# COMMAND LINE ARGUMENTS -------------------------------------------------
# all vars are prepended with "gm_" to avoid overriding other global vars
# default options
gm_verb=0
gm_sil=""
gm_dir=""
gm_branch="master"
gm_main=0
gm_freq=5
gm_reps=100
......@@ -63,31 +68,44 @@ gm_backup=0
gm_files=()
# process command line arguments
while getopts d:D:f:r:R:Bh opt; do
while getopts vsd:D:b:f:r:R:Bh opt; do
case "${opt}" in
d) gm_dir=${OPTARG};;
D)
v) gm_verb=1;; # verbose output
s) gm_sil="-q";; # silence summaries
d) gm_dir=${OPTARG};; # repo directory from working dir
D) # repo directory from main dir
gm_dir=${OPTARG}
gm_main=1;;
f)
b) # branch name
gm_branch=${OPTARG};;
f) # frequency
if (( ${OPTARG} > 0 )); then
gm_freq=${OPTARG}
else
echo "Interval must be greater than 0, will remain 5 mins."
fi;;
r)
r) # reps
if (( ${OPTARG} > 0 )); then
gm_reps=${OPTARG}
else
echo "Number of commits must be greater than 0, will remain 100."
fi;;
R)
R) # repair directory
gm_dir=${OPTARG}
gm_repair=1;;
B) gm_backup=1;;
h)
B) gm_backup=1;; # keep backup
h) # program usage and synopsis
gm_usage
exit
exit;;
esac
done
......@@ -116,7 +134,7 @@ if (( $gm_repair == 1 )); then
# test if gm_dir is a valid repo
if [[ $gm_url == "" ]]; then
echo "$gm_dir is not a repository, exitting program."
echo "$gm_dir is not a repository or the remote repository URL is corrupt, exitting program."
exit
fi
......@@ -172,6 +190,27 @@ if [[ $(git config --get remote.origin.url) == "" ]]; then
exit
fi
# move into branch
if [[ $gm_branch == "" ]]; then
echo "A branch name must be specified, remaining in master branch."
gm_branch="master"
fi
# create branch if it does not exist
if [[ $(git rev-parse --quiet --verify $gm_branch) == "" ]]; then
git branch $gm_branch
git checkout $gm_branch
git push $gm_sil --set-upstream origin $gm_branch
echo "Created new branch $gm_branch."
else
git checkout $gm_branch
fi
echo "Moved to $gm_branch branch."
git branch
# PROGRAM RUNTIME LOOP ---------------------------------------------------
gm_sreps=0 # counts how many reps were completed while program was running
gm_cmd="" # stores command if one is used during program runtime
gm_arg="" # stores argument if command requires one
......@@ -188,22 +227,49 @@ while (( $gm_reps > 0 )); do
for gm_ft in "${gm_files[@]}"; do
git add $gm_ft
done
git commit -m "autosaving progress $(date)"
git push
git commit $gm_sil -m "autosaving progress $(date)"
git push $gm_sil
trap - SIGINT
# tracking progress
((gm_reps-=1))
((gm_sreps+=1))
# nice formatting
echo "--------------------------------------------------"
# program input
if (( $gm_reps > 0 )); then
read -t $((gm_freq*60)) -p "Input command, use h for options: " gm_cmd gm_arg
# nice formatting
echo "--------------------------------------------------"
# verbose output
if (( $gm_verb == 1 )); then
echo "$gm_sreps commit(s) made in $(basename $(pwd)) on $gm_branch branch."
echo "Current program runtime: $(( $(( $(date "+%s") - $gm_stime )) / 60 )) min(s)."
echo ""
fi
# program runtime options
read -t $((gm_freq*60)) -p "Input runtime command, use h for options: " gm_cmd gm_arg
case "$gm_cmd" in
q) gm_reps=1;; # quit
v) # toggle verbose output
if (( $gm_verb == 0 )); then
gm_verb=1
echo "Enabling verbose program output."
else
gm_verb=0
echo "Disabling verbose program output."
fi;;
s) # toggle summary silence
if [[ $gm_sil == "-q" ]]; then
gm_sil=""
echo $gm_sil
echo "Unsilencing commit and push summaries."
else
gm_sil="-q"
echo "Silencing commit and push summaries."
fi;;
d) # changed directories
# check for invalid directory
if [[ gm_arg == "" ]]; then
......@@ -227,6 +293,27 @@ while (( $gm_reps > 0 )); do
fi
fi
fi;;
b) # change branch
if [[ $gm_arg == "" ]]; then
git branch
else
gm_branch=$gm_arg
# create branch if ti does not exist
if [[ $(git rev-parse --quiet --verify $gm_branch) == "" ]]; then
git branch $gm_branch
git checkout $gm_branch
git push $gm_sil --set-upstream origin $gm_branch
echo "Created new branch $gm_branch."
else
git checkout $gm_branch
fi
echo "Moved to $gm_branch branch."
git branch
fi;;
f) # change interval
if (( $gm_arg > 0 )); then
gm_freq=$gm_arg
......@@ -234,18 +321,50 @@ while (( $gm_reps > 0 )); do
else
echo "Interval must be greater than 0."
fi;;
a) # add file
gm_files+=( $gm_arg )
echo "Added $gm_arg to the commit list.";;
h) gm_options;; # input options
if [[ $gm_arg == "" ]]; then
echo "A file name must be specified."
else
gm_files+=( $gm_arg )
echo "Added $gm_arg to the commit list."
fi;;
r) # remove file
if [[ $gm_arg == "" ]]; then
echo "A file name must be specified."
else
gm_i=0
for gm_fname in "${gm_files[@]}"; do
if [[ $gm_fname == $gm_arg ]]; then
unset gm_files[$gm_i]
echo "Removed $gm_arg from the commit list."
else
((gm_i+=1))
fi
done
if (( $gm_i > ${#gm_files[@]} )); then
echo "$gm_arg was not found in the commit list."
fi
fi;;
l) # print commit list
echo "Current file names in the commit list:"
echo "${gm_files[*]}";;
h) gm_options;; # runtime options
esac
fi
# nice formatting
echo ""
echo "--------------------------------------------------"
done
# OUTPUT AND PROGRAM END -------------------------------------------------
# program output
gm_total_t=$(( $(( $(date "+%s") - $gm_stime )) / 60 )) # minutes since loop started
......
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