]> git.phdru.name Git - git-scripts.git/commitdiff
Feat: `sharedRepo [-a|-g] [group]`
authorOleg Broytman <phd@phdru.name>
Sat, 13 Aug 2022 12:45:36 +0000 (15:45 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 13 Aug 2022 12:45:36 +0000 (15:45 +0300)
sharedRepo [new file with mode: 0755]
sharedRepoGroup [deleted file]

diff --git a/sharedRepo b/sharedRepo
new file mode 100755 (executable)
index 0000000..317bd75
--- /dev/null
@@ -0,0 +1,40 @@
+#! /bin/sh
+# See https://stackoverflow.com/a/69193032/7976758
+
+set -e
+share=group
+
+while getopts agh opt; do
+   case $opt in
+      a) share=all ;;
+      g) share=group ;;
+      h) ;;
+   esac
+done
+shift `expr $OPTIND - 1`
+
+if [ $# -gt 1 -o "$1" = -h ]; then
+    echo "Usage: $0 [-a|-g] [group]"
+    if [ $# -gt 1 ]; then
+        exit 1
+    fi
+fi
+
+git config core.sharedRepository $share
+
+# Fix group
+if [ -n "$1" ]; then
+    chgrp -R $1 . # Use desired group name
+    # Make FS to inherit group on creating subdirectories or files
+    find . -type d -exec chmod g+s '{}' \+
+fi
+
+# Fix file/directory permissions throughout the entire tree
+if [ $share = all ]; then
+    chmod -R ug=rwX,o=rX . # Please note **uppercase** X
+    # Git object DB files are read-only
+    find .git/objects -type f -exec chmod a=r '{}' \+
+else # share = group
+    chmod -R ug=rwX,o= .
+    find .git/objects -type f -exec chmod ug=r '{}' \+
+fi
diff --git a/sharedRepoGroup b/sharedRepoGroup
deleted file mode 100755 (executable)
index 3221540..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#! /bin/sh
-# See https://stackoverflow.com/a/69193032/7976758
-
-set -e
-git config core.sharedRepository group
-
-# Fix group
-chgrp -R $1 . # Use desired group name
-
-# Fix file/directory permissions throughout the entire tree
-chmod -R ug+rwX . # Please note **uppercase** X
-
-# Make FS to inherit group on creating subdirectories or files
-find . -type d -exec chmod g+s '{}' \+
-
-# Git object DB files are read-only
-find .git/objects -type f -exec chmod ug=r '{}' \+
-