git/list[1] front-page[2] threads[3] people[4] search[5] about
 

sharedRepository derived from file permissions

From
MHMark Hills <mark@pogo.org.uk>
Date
Oct 8, 2012, 09:07 UTC
Message-ID
<1210080955590.12283@wes.ijneb.com>

We make extensive use of unix permissions and core.sharedRepository -- multiple developers push to the same repo.

I have often wondered why core.sharedRepository is needed at all as a separate configuration?

It looks like it might be easier (and less confusing to users) to derive this attribute from the top-level .git directory?

For many years in our organisation we have been using the scripts below to make it easier for users to configure a repository -- a one-time operation.

Is there a reason why Git doesn't just follow (and echo) the top-level permissions?

Many thanks
-- 
Mark


#!/bin/bash
#
# Propagate permissions of the top-level directory through a repository,
# and configure it for use.
#

if [ "$1" = "--help" ]; then
	echo "Usage: $0 <bare_git_repo>.git"
	echo "Fix permissions on a Git repository, based on the permissions"
	echo "at the top level directory."
	exit 0
fi

if [ -z "$1" ]; then
	echo "Repository argument is mandatory (see --help); aborting."
	exit 1
fi

REPO="$1"

if [ ! -d "$REPO/objects" -o ! -f "$REPO/config" -o ! -f "$REPO/HEAD" ]; then
	echo "$REPO does not look like a bare Git repository; aborting."
	exit 1
fi

# Fix ownership
chown -cR --reference="$REPO" "$REPO"/*

# Fix all the directory permissions after ownership (setting ownership
# removes setgid bit)
find "$REPO" -type d | xargs chmod -c --reference="$REPO"

# Fix files
find "$REPO" -type f | xargs chmod --reference="$REPO"
find "$REPO" -type f | xargs chmod a-sx

# Tidy up; permissions on object files are always 444
find "$REPO/objects" -type f | xargs chmod 0444

# Configure the repository to remove the need for further fixes
# by basing core.SharedRepository on the top level permissions
PERM=0`stat -c '%a' "$REPO"`
MODE=`printf %04o $(($PERM&0666))` # bash required
if [ "$MODE" = "0660" ]; then
	MODE=group
elif [ "$MODE" = "0666" ]; then
	MODE=all
fi
git --git-dir "$REPO" repo-config core.sharedRepository "$MODE"
chmod --reference="$REPO" "$REPO/config"
chmod a-sx "$REPO/config"
Next: Junio C Hamano
Message 1 of 5 in “sharedRepository derived from file permissions”
  1. Mark HillsOct 8, 2012
  2. Junio C HamanoOct 8, 2012
  3. Mark HillsOct 16, 2012
  4. Junio C HamanoOct 17, 2012
  5. Mark HillsOct 17, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.