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
|
#!/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 "upstream-repo"
# 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"
if ! git remote show | grep -qx upstream-repo ; then
info "Git remote 'upstream-repo' 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 'upstream-repo' with URL '$REPOURL' ..."
git remote add upstream-repo "$REPOURL"
git fetch upstream-repo
fi
else
warn "No upstream Git URL found in 'debian/upstream/metadata'. Run 'git remote add upstream-repo <URL>' manually to track upstream."
fi
else
info "Found Git remote 'upstream-repo':"
git remote --verbose show upstream-repo || true
if [ "$UPDATE" -eq "1" ] ; then
OLDREPOURL=$(git remote get-url upstream-repo)
repofrommetadata
if [ -n "$REPOURL" -a "$OLDREPOURL" != "$REPOURL" ] ; then
checkrepourl
if [ -n "$REPOURL" ] ; then
git remote set-url upstream-repo "$REPOURL"
info "Updating Git remote 'upstream-repo' to use URL '$REPOURL' ..."
git remote --verbose show upstream-repo
fi
fi
fi
git fetch --prune upstream-repo || true
fi
POD=<<'EOF'
=head1 NAME
dpt-upstream-repo - add upstream Git repository as git remote upstream-repo
=head1 SYNOPSIS
B<dpt upstream-repo> [-g|-u]
=head1 DESCRIPTION
B<dpt upstream-repo> adds the upstream Git repository as a B<git remote>
named I<upstream-repo>. 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)>.
=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<upstream-repo> 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
=head1 SEE ALSO
L<dpt-debian-upstream(1)>
=head1 COPYRIGHT & LICENSE
=over
=item Copyright 2013-2022 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 term as perl.
=cut
EOF
|