git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook
@ 2006-12-20  9:01 Andy Parkins
  2006-12-20 10:08 ` Andy Parkins
  2006-12-20 19:37 ` Junio C Hamano
  0 siblings, 2 replies; 11+ messages in thread
From: Andy Parkins @ 2006-12-20  9:01 UTC (permalink / raw)
  To: git

Make a file called .gitmodules.  In it, list the paths containing a
submodule.  Add that file to the index.

This addition to the pre-commit hook finds that file and pulls the HEAD
hash out of each of the listed submodule repositories.  That hash is
then listed to the .gitmodules file along with the submodule name and
.gitmodules is added back to the repository.

You've now got poor-man's submodule support.  Any commits to the
submodule will change the hash and hence the .gitmodules file will be
different and therefore will show up as "modified" to git.

It's not got any nice UI for checking out (obviously) or merging; but it
does at least record the state of a project with a bit of manual work to
check out the right commit in the submodule.

Problems:
 - git-prune in the submodule could destroy supermodule-referenced
   commits
 - no checkout support
 - no merge support (other than what git provides for the .gitmodule
   file)
 - no check for dirty submodule before commit

Signed-off-by: Andy Parkins <andyparkins@gmail.com>
---
 templates/hooks--pre-commit |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/templates/hooks--pre-commit b/templates/hooks--pre-commit
index 723a9ef..7a71d81 100644
--- a/templates/hooks--pre-commit
+++ b/templates/hooks--pre-commit
@@ -67,5 +67,34 @@ perl -e '
 	}
     }
     exit($found_bad);
-'
+' || exit 1
+
+# Enable poor-man's submodule support when .gitmodules is present
+# Simply create a .gitmodules file listing the paths in your repository
+# that contain other git repositories; each line will be replaced with the
+# path followed by the hash of the current HEAD of the submodule.
+# When the submodule changes hash this file will be different from the
+# version in the repository and a change will be noted - voila, submodules.
+# Of course there is no checkout support, but at least the current state
+# will be accurately recorded
+if [ -f .gitmodules ]; then
+	cat .gitmodules |
+	while read subdir hash
+	do
+		# XXX: check if the line is a comment
+
+		# XXX: really need a check here and quit if the submodule is
+		# dirty
+
+		echo "$subdir $(GIT_DIR=$subdir/.git git-rev-parse HEAD)"
+	done > .gitmodules
+
+	# This relies on the .gitmodules file having already been added to
+	# the repository - perhaps this should be automated?
+	git-update-index .gitmodules ||
+	(
+	echo "Submodule tracker file is not tracked by this repository." >&2
+	exit 1
+	)
+fi
 
-- 
1.4.4.2.g95ee-dirty

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-12-21  8:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-20  9:01 [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook Andy Parkins
2006-12-20 10:08 ` Andy Parkins
2006-12-20 11:49   ` Brian Gernhardt
2006-12-20 12:01     ` Jakub Narebski
2006-12-20 12:35       ` Andreas Ericsson
2006-12-20 14:47         ` [BUG] git --git-dir dies with bus error Brian Gernhardt
2006-12-20 11:59   ` [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook Jakub Narebski
2006-12-20 12:11     ` Andy Parkins
2006-12-20 19:37 ` Junio C Hamano
2006-12-21  8:39   ` Andy Parkins
2006-12-21  8:49     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).