git-secure-export

Experimental tooling for encrypting the git-fast-export(1) output

git clone https://git.8pit.net/git-secure-export.git

 1#!/bin/sh
 2# Copyright (c) 2012 Felipe Contreras
 3#
 4# Slightly modified version of git-remote-testgit(1). Copied from the
 5# git-2.27 source tree (t/t5801/git-remote-testgit). As it was copied
 6# from Git itself, it is licensed under the GNU General Public License
 7# version 2. Refer to the git-2.27 source tree for further license
 8# information.
 9#
10# This file is intended to be installed to $PATH on your git server.
11
12if [ $# -ne 1 ]; then
13	echo "USAGE: ${0##*/} GIT_REPOSITORY" 1>&2
14	exit 1
15fi
16
17GIT_DIR="${1}/$(git -C "${1}" rev-parse --git-dir)"
18export GIT_DIR
19
20if [ ! -d "${GIT_DIR}" ]; then
21	echo "Repository '${GIT_DIR}' does not exist" 1>&2
22	exit 1
23fi
24
25dir="$GIT_DIR/secure"
26mkdir -p "$dir"
27
28h_refspec="refs/heads/*:refs/testgit/heads/*"
29t_refspec="refs/tags/*:refs/testgit/tags/*"
30
31while read line
32do
33	case $line in
34	capabilities)
35		echo 'import'
36		echo 'export'
37		test -n "$h_refspec" && echo "refspec $h_refspec"
38		test -n "$t_refspec" && echo "refspec $t_refspec"
39		echo
40		;;
41	list)
42		git for-each-ref --format='? %(refname)' 'refs/heads/' 'refs/tags/'
43		head=$(git symbolic-ref HEAD)
44		echo "@$head HEAD"
45		echo
46		;;
47	import*)
48		# read all import lines
49		while true
50		do
51			ref="${line#* }"
52			refs="$refs $ref"
53			read line
54			test "${line%% *}" != "import" && break
55		done
56
57		echo "feature done"
58		git fast-export \
59			--refspec="$h_refspec" \
60			--refspec="$t_refspec" \
61			$refs
62		echo "done"
63		;;
64	export)
65		before=$(git for-each-ref --format=' %(refname) %(objectname) ')
66		
67		# As file contents are encrypted, files on the git
68		# server have a different checksum than local files,
69		# i.e. the entire commit history is different. For this
70		# reason force pushing is required and likely unavoidable.
71		git fast-import \
72			--force \
73			--quiet
74
75		# figure out which refs were updated
76		git for-each-ref --format='%(refname) %(objectname)' |
77		while read ref a
78		do
79			case "$before" in
80			*" $ref $a "*)
81				continue ;;	# unchanged
82			esac
83			
84			echo "ok $ref"
85		done
86
87		echo
88		;;
89	'')
90		exit
91		;;
92	esac
93done