]> gitweb.fluxo.info Git - utils-git.git/commitdiff
Fix: git-config-save: adds --sometimes flag
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 23 Apr 2021 12:13:26 +0000 (09:13 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 23 Apr 2021 12:13:26 +0000 (09:13 -0300)
git-config-save

index 5c040e481b9dd4b776d8cf6cbf21c083ab5d2a80..dad19ef0054a9a8475d83451355a12b73bfe43f3 100755 (executable)
@@ -51,6 +51,9 @@ BASENAME="`basename $0`"
 BASE="$HOME/.config/gitconfigs"
 DATE="`date +%Y%m%d%I%M%S`"
 FILENAME="gitconfig.saved"
+OPTION="$1"
+COUNTER="$BASE/counter"
+SOMETIMES="20"
 
 # Ensure we have a base and that is minimally safe
 mkdir -p  $BASE
@@ -125,6 +128,24 @@ function git_config_restore {
   echo "Backup saved at $pwd/.git/config.$DATE"
 }
 
+# Check option
+if [ ! -z "$OPTION" ] && [ "$OPTION" == "--sometimes" ]; then
+  if [ ! -e "$COUNTER" ]; then
+    echo 0 > $COUNTER
+  fi
+
+  COUNT="`cat $COUNTER`"
+
+  if (($COUNT >= $SOMETIMES)); then
+    echo 0 > $COUNTER
+  else
+    let COUNT++
+    echo $COUNT > $COUNTER
+    echo "Running only sometimes. This is run ${COUNT} of ${SOMETIMES}, skipping."
+    exit 1
+  fi
+fi
+
 # Process everything we can find
 find -type d -name .git | while read repo; do
   # Get absolute folder