[coreboot-gerrit] Change in coreboot[master]: util/gitconfig: Make gitconfig.sh support gitfile

Alex Thiessen (Code Review) gerrit at coreboot.org
Sun Jan 14 00:31:38 CET 2018


Alex Thiessen has uploaded this change for review. ( https://review.coreboot.org/23253


Change subject: util/gitconfig: Make gitconfig.sh support gitfile
......................................................................

util/gitconfig: Make gitconfig.sh support gitfile

The `gitconfig.sh` script installs hooks to the according directories (for
coreboot and its submodules). It has the `hooks` directory hard-coded to be
`.git/hooks`, which makes the installation fail when coreboot itself is a
submodule because then `.git` becomes a gitfile.

Replace hard-coded path handling using the according `git rev-parse` calls.

Change-Id: I778e20be24bb27d0081c9e1c12883117d6d50347
Signed-off-by: Alex Thiessen <alex.thiessen+coreboot at gmail.com>
---
M util/gitconfig/gitconfig.sh
1 file changed, 22 insertions(+), 14 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/53/23253/1

diff --git a/util/gitconfig/gitconfig.sh b/util/gitconfig/gitconfig.sh
index 42f613e..6395c7c 100755
--- a/util/gitconfig/gitconfig.sh
+++ b/util/gitconfig/gitconfig.sh
@@ -15,26 +15,34 @@
 ## GNU General Public License for more details.
 ##
 
-if [ ! -d .git ]; then
-	echo "Error: Not in a git repository"
+if ! { cdup="$(git rev-parse --show-cdup 2>/dev/null)" && [ -z "${cdup}" ]; }
+then
+	echo "Error: Not in root of a git repository"
 	exit 1
 fi
-mkdir -p .git/hooks
+coreboot_gitdir=$(git rev-parse --git-dir)
+coreboot_hooks=${coreboot_gitdir}/hooks
+mkdir -p "${coreboot_hooks}"
 for hook in commit-msg pre-commit ; do
-	if [ util/gitconfig/$hook -nt .git/hooks/$hook ] || \
-		[ ! -x .git/hooks/$hook ]; then
-		sed -e "s,%MAKE%,remake,g" util/gitconfig/$hook > .git/hooks/$hook
-		chmod +x .git/hooks/$hook
+	if [ util/gitconfig/${hook} -nt "${coreboot_hooks}/${hook}" ] \
+		|| [ ! -x "${coreboot_hooks}/${hook}" ]
+	then
+		sed -e "s,%MAKE%,remake,g" util/gitconfig/$hook \
+			> "${coreboot_hooks}/${hook}"
+		chmod +x "${coreboot_hooks}/${hook}"
 	fi
 done
 # Now set up the hooks for 3rdparty/
-for hooks in .git/modules/{3rdparty/blobs,libhwbase,libgfxinit}/hooks; do
-	if [ -d $hooks ]; then
-		if [ util/gitconfig/commit-msg -nt $hooks/commit-msg ] || \
-			[ ! -x $hooks/commit-msg ]; then
-			sed -e "s,%MAKE%,remake,g" \
-				util/gitconfig/commit-msg > $hooks/commit-msg
-			chmod +x $hooks/commit-msg
+for submodule in 3rdparty/blobs libhwbase libgfxinit; do
+	hooks=$(git -C "$(git config --file .gitmodules --get \
+		submodule.${submodule}.path)" rev-parse	--git-dir)/hooks
+	if [ -d "${hooks}" ]; then
+		if [ util/gitconfig/commit-msg -nt "${hooks}/commit-msg" ] \
+			|| [ ! -x "${hooks}/commit-msg" ]
+		then
+			sed -e "s,%MAKE%,remake,g" util/gitconfig/commit-msg \
+				> "${hooks}/commit-msg"
+			chmod +x "${hooks}/commit-msg"
 		fi
 	fi
 done

-- 
To view, visit https://review.coreboot.org/23253
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I778e20be24bb27d0081c9e1c12883117d6d50347
Gerrit-Change-Number: 23253
Gerrit-PatchSet: 1
Gerrit-Owner: Alex Thiessen <alex.thiessen.de+coreboot at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180113/40456ae7/attachment.html>


More information about the coreboot-gerrit mailing list