aboutsummaryrefslogtreecommitdiff
path: root/commit.sh
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-11-05 00:01:23 -0400
committerBobby <[email protected]>2022-11-05 00:01:23 -0400
commit565837f28afe629e1044ccd079182dc07d94be37 (patch)
treed3b19a595cf6d95b5cd9b8f208dbf120c9d0c399 /commit.sh
parent3ea91870534b67d546b3c14603e655cbfae0429b (diff)
downloadtexty-565837f28afe629e1044ccd079182dc07d94be37.tar.xz
texty-565837f28afe629e1044ccd079182dc07d94be37.zip
Created a file committer
Diffstat (limited to 'commit.sh')
-rwxr-xr-xcommit.sh84
1 files changed, 84 insertions, 0 deletions
diff --git a/commit.sh b/commit.sh
new file mode 100755
index 0000000..878714a
--- /dev/null
+++ b/commit.sh
@@ -0,0 +1,84 @@
+# This script is used to process certain files or run certain commands
+# before a commit is made. You should use this script instead of
+# using the any of the git commands directly.
+
+# This script is called with the following arguments:
+# $1 - files to be committed (space separated) or '.' if all files
+# $2 - commit message preceded by a '-m'
+# $3 - change type (optional) - valid values are 'feat', 'fix',
+# 'docs', 'style', 'refactor', 'perf', 'test', 'chore' or
+# 'revert'. If not specified, 'feat' is assumed. Must be
+# specified preceded by a '-t' flag.
+# $4 - branch name (optional) - if not specified, the current branch
+# is assumed. Must be specified preceded by a '-b' flag.
+
+# This script should return 0 if the commit should proceed or 1 if
+# the commit should be aborted.
+
+# Get the current branch name
+branch=$(git rev-parse --abbrev-ref HEAD)
+
+# Get arguments passed to this script
+files=$1
+message=$2
+type=$3
+branch=$4
+
+# Check if the branch name is specified
+if [ "$branch" != "" ]; then
+ # Check if the branch name is valid
+ if [ $(git branch | grep -c "$branch") -eq 0 ]; then
+ echo "Branch $branch does not exist"
+ exit 1
+ fi
+fi
+
+# Check if the change type is specified
+if [ "$type" != "" ]; then
+ # Check if the change type is valid
+ if [ $(echo $type | grep -c "feat\|fix\|docs\|style\|refactor\|perf\|test\|chore\|revert") -eq 0 ]; then
+ echo "Invalid change type $type"
+ exit 1
+ fi
+fi
+
+# Check if the commit message is specified, if not, prompt the user
+if [ "$message" = "" ]; then
+ echo "Enter commit message (required):"
+ read message
+fi
+
+
+# Check if files are specified, if not, prompt the user
+if [ "$files" = "" ]; then
+ echo "Enter files to be committed (space separated) or '.' for all files (required):"
+ read files
+fi
+
+
+# Generate requirements.txt file, delete it if it already exists
+if [ -f requirements.txt ]; then
+ rm requirements.txt
+fi
+pip3 freeze > requirements.txt
+
+
+# Add files to be committed
+git add $files
+git add requirements.txt
+
+# Modify the message in the following format: <type>: <message>
+if [ "$type" != "" ]; then
+ message="$type: $message"
+fi
+
+# Commit the changes
+git commit -m "$message"
+
+# Push the changes to the remote branch
+if [ "$branch" != "" ]; then
+ git push origin $branch
+else
+ git push origin $branch
+fi
+