commit d3ea9a9df63e792ce68a4fed4817cc9078727581
parent 61bbba820ec921107da87ef8f5c32011fbff68a3
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 25 Sep 2024 15:48:59 +0200
Forbidding privatisation of a shared repository
Until now, the change of owner failed because certain files did not
belong to the user, leaving him to interpret what was wrong on his own.
Now, the script checks that the user is the owner of the repository
before privatising it, otherwise it displays an error message explaining
why it stops unexpectedly. This not only makes the error clearer, but
also avoids any changes to file permissions if the entire process cannot
be run, i.e. if the repository cannot be privatised, it remains shared.
Diffstat:
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/git-repo b/git-repo
@@ -43,7 +43,17 @@ share() # repo, group
# Do not share the repository and define the group as the user's group
else
+
+ u="$(id -un)"
g="$(id -gn)"
+
+ f="$(find "$1" ! -user "${u}")"
+ if [ -n "${f}" ]; then
+ >&2 printf 'The repository cannot be privatised: '\
+'some files do not belong to %s\n' "${u}"
+ die
+ fi
+
chown -R :"${g}" "$1"
find "$1" -type f -exec chmod "g-w" {} \;
find "$1" -type d -exec chmod "g-ws" {} \;