File: tg-remote.sh

package info (click to toggle)
topgit 0.8-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 336 kB
  • sloc: sh: 1,573; makefile: 38
file content (68 lines) | stat: -rw-r--r-- 2,090 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
# TopGit - A different patch queue manager
# (c) Petr Baudis <pasky@suse.cz>  2008
# GPLv2

populate= # Set to 1 if we shall seed local branches with this
name=


## Parse options

while [ -n "$1" ]; do
	arg="$1"; shift
	case "$arg" in
	--populate)
		populate=1;;
	-*)
		echo "Usage: tg [...] remote [--populate] REMOTE" >&2
		exit 1;;
	*)
		name="$arg";;
	esac
done

git config "remote.$name.url" >/dev/null || die "unknown remote '$name'"


## Configure the remote

git config --replace-all "remote.$name.fetch" "+refs/top-bases/*:refs/remotes/$name/top-bases/*" "\\+refs/top-bases/\\*:refs/remotes/$name/top-bases/\\*"

if git config --get-all "remote.$name.push" "\\+refs/top-bases/\\*:refs/top-bases/\\*" >/dev/null && test "xtrue" != "x$(git config --bool --get topgit.dontwarnonoldpushspecs)"; then
	info "Probably you want to remove the push specs introduced by an old version of topgit:"
	info '       git config --unset-all "remote.'$name'.push" "\\+refs/top-bases/\\*:refs/top-bases/\\*"'
	info '       git config --unset-all "remote.'$name'.push" "\\+refs/heads/\\*:refs/heads/\\*"'
	info '(or use git config --bool --add topgit.dontwarnonoldpushspecs true to get rid of this warning)'
fi

info "Remote $name can now follow TopGit topic branches."
if [ -z "$populate" ]; then
	info "Next, do: git fetch $name"
	exit
fi


## Populate local branches

info "Populating local topic branches from remote '$name'..."

git fetch "$name"
git for-each-ref "refs/remotes/$name/top-bases" |
	while read rev type ref; do
		branch="${ref#refs/remotes/$name/top-bases/}"
		if git rev-parse "$branch" >/dev/null 2>&1; then
			git rev-parse "refs/top-bases/$branch" >/dev/null 2>&1 ||
				git update-ref "refs/top-bases/$branch" "$rev"
			info "Skipping branch $branch: Already exists"
			continue
		fi
		info "Adding branch $branch..."
		git update-ref "refs/top-bases/$branch" "$rev"
		git update-ref "refs/heads/$branch" "$(git rev-parse "$name/$branch")"
	done

git config "topgit.remote" "$name"
info "The remote '$name' is now the default source of topic branches."

# vim:noet