summary refs log tree commit diff stats
path: root/git-init-remote
blob: 71b9dd4a85f71bde52802c5422352c1f4cb553f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh

GITREMOTE=git.acdw.net
GITROOT=/git

POSTUPDATEHOOK=/tmp/post-update.hook

init_post_update_hook() {
	# This post-update hook will update cgit's date display.
	cat <<\EOF
#!/bin/sh

# Update "agefile" for cgit
# The default location is <git-dir>/info/web/last-modified
agefile="$(git rev-parse --git-dir)/info/web/last-modified"
mkdir -p "$(dirname "$agefile")"

git for-each-ref > "$agefile" \
	--sort=-authordate --count=1 \
	--format='%(authordate:iso8601)'

# Prepare a packed repository for use over dumb transports
git update-server-info
EOF
}

## Setup

git ls-files > /dev/null || exit 1

test -f "$POSTUPDATEHOOK" || init_post_update_hook > "$POSTUPDATEHOOK"

# consider --git-dir as well .. however --git-dir would require more massaging
# of the output.
local="$(git rev-parse --show-toplevel)"
name="${local##*/}"

remote="$GITROOT/$name.git"

## Remote work

# Initiate the repository
echo "ssh \"$GITREMOTE\" git init --bare \"$remote\""
ssh "$GITREMOTE" git init --bare "$remote"

# Add a description
echo "ssh \"$GITREMOTE\" ed \"$remote/description\""
ssh "$GITREMOTE" ed "$remote/description"

# Add post-update-hook
echo "scp \"$POSTUPDATEHOOK\" \"$GITREMOTE:$remote/hooks/post-update\""
scp "$POSTUPDATEHOOK" "$GITREMOTE:$remote/hooks/post-update"
echo "ssh \"$GITREMOTE\" chmod +x \"$remote/hooks/post-update\""
ssh "$GITREMOTE" chmod +x "$remote/hooks/post-update"

## Local work

echo "git remote add origin \"$GITREMOTE:$remote\""
git remote add origin "$GITREMOTE:$remote"

echo -n "Push to remote? "
read

case "$REPLY" in
	y*|Y*|'')
		branch="$(git branch --show-current)"
		echo git push -u origin "$branch"
		git push -u origin "$branch"
		;;
	*) ;;
esac