File: upstreamvcs

package info (click to toggle)
pkg-perl-tools 0.85
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 796 kB
  • sloc: perl: 3,254; sh: 3,244; makefile: 144; python: 18
file content (173 lines) | stat: -rwxr-xr-x 4,118 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/sh

# copyright, licensing and documentation at the end

set -e
set -u

. "${DPT__SCRIPTS:-/usr/share/pkg-perl-tools}/lib/dpt-lib.sh"

# functions

repofrommetadata() {
	# XXX use something better than awk to parse this YAML file?
	REPOURL=$(awk '/^Repository:\s*.+/ {print $2;}' debian/upstream/metadata || true)
}

checkrepourl() {
	if ! GIT_ASKPASS=/bin/true git ls-remote "$REPOURL" >/dev/null 2>&1; then
		REPOURL=
	fi
}

# default values

CREATE=1
UPDATE=0
REPOURL=

# command line arguments
# -g don't create debian/upstream/metadata
# -u update url of remote "upstreamvcs"
#    to be used from .mrconfig
while getopts gu OPTS; do
	case "$OPTS" in
		g)
			CREATE=0
			;;
		u)
			UPDATE=1
			CREATE=0
			;;
		*)
			;;
	esac
done
shift $((OPTIND -1))

# "main"

# rename upstream-repo to upstreamvcs
if git remote show | grep -qx upstream-repo ; then
	info "Rename Git remote 'upstream-repo' to 'upstreamvcs'."
	git remote rename upstream-repo upstreamvcs
fi

if ! git remote show | grep -qx upstreamvcs ; then
	info "Git remote 'upstreamvcs' not found, trying to add it ..."

	if [ ! -e debian/upstream/metadata -a "$CREATE" -eq "1" ] ; then
		warn "No 'debian/upstream/metadata' file found, trying to create it ..."
		dpt debian-upstream || true
		if [ -e debian/upstream/metadata ] ; then
			git add debian/upstream/metadata
			git commit -m "Add debian/upstream/metadata"
			dch --no-auto-nmu --mainttrailer --release-heuristic=changelog "Add debian/upstream/metadata"
			git add debian/changelog
			git commit -m "Update debian/changelog" -m "Gbp-Dch: Ignore"
		fi
	fi

	if [ -e debian/upstream/metadata ] ; then
		repofrommetadata
	fi

	if [ -n "$REPOURL" ] ; then
		checkrepourl
		if [ -n "$REPOURL" ] ; then
			info "Adding Git remote 'upstreamvcs' with URL '$REPOURL' ..."
			git remote add upstreamvcs "$REPOURL"
			git fetch upstreamvcs
		fi
	else
		warn "No upstream Git URL found in 'debian/upstream/metadata'. Run 'git remote add upstreamvcs <URL>' manually to track upstream."
	fi
else
	info "Found Git remote 'upstreamvcs':"
	git remote --verbose show upstreamvcs || true
	if [ "$UPDATE" -eq "1" ] ; then
		OLDREPOURL=$(git remote get-url upstreamvcs)
		repofrommetadata
		if [ -n "$REPOURL" -a "$OLDREPOURL" != "$REPOURL" ] ; then
			checkrepourl
			if [ -n "$REPOURL" ] ; then
				git remote set-url upstreamvcs "$REPOURL"
				info "Updating Git remote 'upstreamvcs' to use URL '$REPOURL' ..."
				git remote --verbose show upstreamvcs
			fi
		fi
	fi
	git fetch --prune upstreamvcs || true
fi

POD=<<'EOF'
=head1 NAME

dpt-upstreamvcs - add upstream Git repository as git remote upstreamvcs

=head1 SYNOPSIS

B<dpt upstreamvcs> [-g|-u]

=head1 DESCRIPTION

B<dpt upstreamvcs> adds the upstream Git repository as a B<git remote>
named I<upstreamvcs>. The URL for the repository is read from
F<debian/upstream/metadata>'s I<Repository> field.

In case F<debian/upstream/metadata>
doesn't exist, it is created with L<dpt-debian-upstream(1)>.

In case a Git remote called I<upstream-repo> exists, it is renamed to
I<upstreamvcs>.

=head1 OPTIONS

=over

=item B<-g>

Don't create F<debian/upstream/metadata>.

Used for initial cloning, e.g. with B<mr up>: We want the upstream
repo being added if debian/upstream/metadata exists.

The letter B<g> is used for historical reasons because initially this
option only suppressed the automatic committing to the B<g>it
repository.

=item B<-u>

Update the URL of the I<upstreamvcs> B<git remote>.
The value is read from the same places as for the initial creation.

B<-u> implies B<-g>, i.e. we also don't create F<debian/upstream/metadata>
on updates.

=back

B<dpt upstream-repo> (the old name of this subcommand) is an alias for B<dpt
upstreamvcs>.

=head1 SEE ALSO

L<dpt-debian-upstream(1)>

=head1 COPYRIGHT & LICENSE

=over

=item Copyright 2013-2025 gregor herrmann L<gregoa@debian.org>

=item Copyright 2014 David Bremner L<bremner@debian.org>

=item Copyright 2015 Axel Beckert L<abe@debian.org>

=item Copyright 2016 Alex Muntada L<alexm@alexm.org>

=back

This program is free software, licensed under the same terms as perl.

=cut
EOF