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

[PATCH] [TopGit] Check for pre-commit hook existence.

From
RSRussell Steicke <russellsteicke@gmail.com>
Date
Aug 3, 2008, 14:14 UTC
Message-ID
<20080803141030.GC11179@maggie.localnet>
In-Reply-To
<20080803031424.GV32184@machine.or.cz>

Running tg in a repo without an active pre-commit hook fails saying

  grep: .git/hooks/pre-commit: No such file or directory
  cat: .git/hooks/pre-commit: No such file or directory

Even "tg help" does this! So add extra checks for existence of the pre-commit hook.

---
 tg.sh |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/tg.sh b/tg.sh
index 56c5709..15005db 100644
--- a/tg.sh
+++ b/tg.sh
@@ -21,9 +21,11 @@ die()
 setup_hook()
 {
 	hook_call="\"\$(tg --hooks-path)\"/$1 \"\$@\""
-	if fgrep -q "$hook_call" "$git_dir/hooks/$1"; then
-		# Another job well done!
-		return
+	if [ -x "$git_dir/hooks/$1" ]; then
+		if fgrep -q "$hook_call" "$git_dir/hooks/$1"; then
+			# Another job well done!
+			return
+		fi
 	fi
 	# Prepare incanation
 	if [ -x "$git_dir/hooks/$1" ]; then
@@ -35,7 +37,7 @@ setup_hook()
 	{
 		echo "#!/bin/sh"
 		echo "$hook_call"
-		cat "$git_dir/hooks/$1"
+		[ -x "$git_dir/hooks/$1" ] && cat "$git_dir/hooks/$1"
 	} >"$git_dir/hooks/$1+"
 	chmod a+x "$git_dir/hooks/$1+"
 	mv "$git_dir/hooks/$1+" "$git_dir/hooks/$1"
-- 
1.6.0.rc1


-- 
Russell Steicke

-- Fortune says:
I got the bill for my surgery.  Now I know what those doctors were
wearing masks for.
		-- James Boren
Previous: Petr BaudisNext: Petr Baudis
Message 4 of 14 in “[ANNOUNCE] TopGit - A different patch queue manager”
  1. Petr BaudisAug 3, 2008
  2. Miklos VajnaAug 3, 2008
  3. Petr BaudisAug 3, 2008
  4. [TopGit] Check for pre-commit hook existence.Russell Steicke, Aug 3, 2008
  5. Petr BaudisAug 3, 2008
  6. Jon SmirlAug 3, 2008
  7. Karl HasselströmAug 4, 2008
  8. linearising TopGit forests into patch series (was: [ANNOUNCE] TopGit - A different patch queue manager)martin f krafft, Aug 7, 2008
  9. Bert WesargAug 7, 2008
  10. martin f krafftAug 8, 2008
  11. Bert WesargAug 8, 2008
  12. Petr BaudisAug 9, 2008
  13. Petr BaudisAug 10, 2008
  14. Sam VilainAug 9, 2008

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.