admin преди 10 години
ревизия
00d8ebdab9
променени са 1 файла, в които са добавени 47 реда и са изтрити 0 реда
  1. 47 0
      gitsave.sh

+ 47 - 0
gitsave.sh

@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# Basic options
+
+# Branch to save in
+branch=work
+
+# Remote to upload to
+remote=origin
+
+
+error() {
+ echo $1
+ exit 1
+}
+
+# Name of current branch
+cb=$(git rev-parse --abbrev-ref HEAD)
+
+# Check if correct branch
+[[ $branch == $cb ]] || error "Working on incorrect branch \"$cb\"!"
+
+# Check if there's anything to commit
+if [ -z "$(git status --porcelain)" ]; then
+ error "Nothing to save!"
+fi
+
+# Name of last commit
+last=$(git log -1 --pretty=%s)
+
+# Check if last commit name is valid
+# Structure must be "commit###" where # is number
+[[ ${#last} -eq 9 ]] || error "Incorrect last commit name length \"$last\"!"
+[[ ${last:0:6} == "commit" ]] || error "Incorrect last commit name \"$last\"!"
+
+# Last commit number
+lcn=${last:6:9}
+
+# Check if integer
+[[ $lcn =~ ^-?[0-9]+$ ]] || error "Incorrect last commit number \"$last\"!"
+
+# New commit number
+printf -v ncn "%03d" $(($lcn + 1))
+git add .
+git commit -m "commit$ncn"
+git push $remote $branch
+echo "Work saved!"