summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorModestas Vainius <modax@debian.org>2012-05-27 15:21:22 +0300
committerModestas Vainius <modax@debian.org>2012-05-27 15:37:57 +0300
commitdb8f05962c34d6e8289014001a5f0ae3b218f100 (patch)
tree3ad26caee74b24d20c2d4f29f5e6b53b7261fb6c
parenta2348c48cb19c96de3a5526c0cf945ce3c37ee79 (diff)
downloadpkg-kde-tools-db8f05962c34d6e8289014001a5f0ae3b218f100.tar.gz
Implement pkgkde-git clone and update-config subcommands.
-rw-r--r--debian/changelog1
-rw-r--r--man1/pkgkde-vcs.147
-rwxr-xr-xpkgkde-vcs16
-rw-r--r--vcslib/git.sh156
4 files changed, 193 insertions, 27 deletions
diff --git a/debian/changelog b/debian/changelog
index a9fb666..f0d48f3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,7 @@ pkg-kde-tools (0.14.5~pre1) UNRELEASED; urgency=low
* Bump Standards-Version to 3.9.3: no changes needed.
* Install pkgkde-git as an alias for pkgkde-vcs with VCS type forced to git.
+ * Implement pkgkde-git clone and update-config subcommands.
-- Modestas Vainius <modax@debian.org> Mon, 21 May 2012 19:42:46 +0300
diff --git a/man1/pkgkde-vcs.1 b/man1/pkgkde-vcs.1
index a788b9c..cec5d05 100644
--- a/man1/pkgkde-vcs.1
+++ b/man1/pkgkde-vcs.1
@@ -68,8 +68,33 @@ specific \fIsubcommand\fR for more details.
.SH SUPPORTED VERSION CONTROL SYSTEMS AND SUBCOMMANDS
.SS Git
In order to use \fBpkgkde\-vcs\fR with Git, \fIgit(1)\fR must be available in \fIPATH\fR.
-Bare Git repositories are not supported and Git repository should be in fully checked out
-state. The following subcommands for Git repositories are supported at the moment:
+Bare Git repositories are not supported and Git repository should be in the fully checked
+out state (except \fBclone\fR). The following subcommands for Git repositories are supported
+at the moment:
+
+.TP
+.B clone
+Clone the specified pkg\-kde git repository. This subcommand should be specified
+by forcing VCS to git, i.e. by running \fIpkgkde\-git\fR command rather than
+\fIpkgkde-vcs\fR.
+
+Repository should be specified relatively to the root of the official pkg-kde
+repository tree. Once operation is complete, the cloned repository will be put
+at the same relative location on the local filesystem and \fBupdate\-config\fR
+(see below) will be executed on it.
+
+For example, in order to clone kde4libs repository from \fIkde\-sc\fR,
+akonadi repository from \fIkde\-req\fR and pkg\-kde\-tools repository from the
+root tree, execute:
+.P
+.RS
+$ pkgkde\-git clone kde\-sc/kde4libs
+.P
+$ pkgkde\-git clone kde\-req/akonadi
+.P
+$ pkgkde\-git clone pkg\-kde\-tools
+.RE
+
.TP
.B tag
Tag current packaging state (HEAD) as upload to Debian archive. Repository
@@ -102,6 +127,24 @@ the hood (assuming version is 1:2.3.4-5 and distribution is experimental):
.RS
$ git tag debian/2.3.4-5 \-m "1:2.3.4-5/experimental"
.RE
+.RE
+
+.TP
+.B update\-config
+Do some common configuration on the checked out packaging repository. At the
+moment, the subcommand performs the following:
+.RS
+.IP \(bu
+Set up master branch and debian tags for pushing. \fB\-f\fR option may be
+specified to force update of the pushing configuration even if some pushing
+configuration already exists.
+.IP \(bu
+Set repository user name and email address to the values of the
+\fBDEBFULLNAME\fR and \fBDEBEMAIL\fR environment variables respectively.
+\fB\-f\fR option may be specified to override the values even if the repository
+has some specified already.
+.RE
+
.SH LICENSE
.P
This program is free software: you can redistribute it and/or modify
diff --git a/pkgkde-vcs b/pkgkde-vcs
index cd7d811..58fca08 100755
--- a/pkgkde-vcs
+++ b/pkgkde-vcs
@@ -159,6 +159,22 @@ is_distribution_valid()
return 1
}
+opt_till_double_dash() {
+ local name
+ # Parse out remaining -- if needed
+ while getopts ":" name; do
+ case "$name" in
+ ?) if [ -n "$OPTARG" ]; then OPTIND=$(($OPTIND-1)); fi; break;;
+ :) die "$OPTARG option is missing a required argument" ;;
+ esac
+ done
+ if [ "$OPTIND" -gt 1 ]; then
+ echo "$(($OPTIND-1))"
+ else
+ echo "0"
+ fi
+}
+
# Parse common options
OPT_VERBOSE=
OPT_PROMPT='prompt'
diff --git a/vcslib/git.sh b/vcslib/git.sh
index 434183b..1c55ee9 100644
--- a/vcslib/git.sh
+++ b/vcslib/git.sh
@@ -18,8 +18,9 @@
git_tag()
{
- local tag_path tag_msg
+ shift $(opt_till_double_dash "$@")
+ local tag_path tag_msg
is_distribution_valid || die "invalid Debian distribution for tagging - $DEB_DISTRIBUTION"
git_is_working_tree_clean || die "working tree is dirty. Commit changes before tagging."
@@ -29,6 +30,101 @@ git_tag()
runcmd git tag $tag_path -m "$tag_msg" "$@"
}
+git_clone()
+{
+ local url pushurl
+ url="git://git.debian.org/pkg-kde"
+ pushurl="git.debian.org:/git/pkg-kde"
+
+ # Parse remaining command line (or -- if any) options
+ local name
+ while getopts ":u:p:" name; do
+ case "$name" in
+ u) url="$OPTARG" ;;
+ p) pushurl="$OPTARG";;
+ ?) if [ -n "$OPTARG" ]; then OPTIND=$(($OPTIND-1)); fi; break;;
+ :) die "$OPTARG option is missing a required argument" ;;
+ esac
+ done
+ if [ "$OPTIND" -gt 1 ]; then
+ shift "$(($OPTIND-1))"
+ fi
+
+ local repo dir
+ repo="${1%.git}"
+ dir="`dirname "$repo"`"
+ shift 1 # Shift repo
+
+ shift $(opt_till_double_dash "$@")
+
+ url="${url}/${repo}.git"
+ pushurl="${pushurl}/${repo}.git"
+
+ if [ -d "$repo" ]; then
+ die "$repo repository already exists locally"
+ fi
+ if [ ! -d "$dir" ]; then
+ die "repository parent directory $dir does not exist on the local filesystem. Create it"
+ fi
+
+ info "Cloning $url (pushurl: $pushurl)"
+ runcmd git clone "$@" -- "$url" "$repo"
+
+ info "Updating configuration of the new repository"
+ cd "$repo"
+ runcmd git config remote.origin.pushurl "$pushurl"
+
+ git_update_config
+}
+
+git_update_config()
+{
+ local force
+
+ # Parse remaining command line (or -- if any) options
+ local name
+ while getopts ":f" name; do
+ case "$name" in
+ f) force="y";;
+ ?) if [ -n "$OPTARG" ]; then OPTIND=$(($OPTIND-1)); fi; break;;
+ :) die "$OPTARG option is missing a required argument" ;;
+ esac
+ done
+ if [ "$OPTIND" -gt 1 ]; then
+ shift "$(($OPTIND-1))"
+ fi
+
+ if [ -n "$force" ] || ! git config --get-all remote.origin.push "$@" > /dev/null; then
+ info "[ok] Setting up repository to push master and debian tags by default."
+ runcmd git config --replace-all remote.origin.push "refs/heads/master"
+ runcmd git config --add remote.origin.push "refs/tags/debian/*"
+ else
+ info "[skip] Push specs already present."
+ fi
+
+ if [ -n "$DEBFULLNAME" ]; then
+ if [ "$force" = "y" ] || ! git config --file=.git/config --get "user.name" "$@" >/dev/null 2>&1; then
+ info "[ok] Setting user.name to the value of the DEBFULLNAME environment variable: $DEBFULLNAME."
+ runcmd git config user.name "$DEBFULLNAME"
+ else
+ info "[skip] user.name configuration option is already set"
+ fi
+ else
+ info "[skip] DEBFULLNAME environment variable is not set. Not setting user.name."
+ fi
+
+ if [ -n "$DEBEMAIL" ]; then
+ if [ "$force" = "y" ] || ! git config --file=.git/config --get "user.email" "$@" >/dev/null 2>&1; then
+ info "[ok] Setting user.email to the value of the DEBEMAIL environment variable: $DEBEMAIL."
+ runcmd git config user.email "$DEBEMAIL"
+ else
+ info "[skip] user.email configuration option is already set"
+ fi
+ else
+ info "[skip] DEBEMAIL environment variable is not set. Not setting user.email."
+ fi
+}
+
git_compat_debver()
{
echo "$1" | tr "~" "-"
@@ -39,34 +135,38 @@ git_is_working_tree_clean()
git update-index --refresh > /dev/null && git diff-index --quiet HEAD
}
-
-PACKAGE_ROOT="$(readlink -f "$(git rev-parse --git-dir)/..")"
-
-# Do some envinronment sanity checks first
-if [ "$(git rev-parse --is-bare-repository)" = "true" ]; then
- die "bare Git repositories are not supported."
-fi
-
-is_valid_package_root "$PACKAGE_ROOT" ||
- die "$PACKAGE_ROOT does NOT appear to be a a valid debian packaging repository"
-
# Get subcommand name
test "$#" -gt 0 || die "subcommand is NOT specified"
subcmd="$1"; shift
-# Get info about debian package
-get_debian_package_info "$PACKAGE_ROOT"
-
-# Parse remaining command line (or -- if any) options
-while getopts ":" name; do
- case "$name" in
- ?) if [ -n "$OPTARG" ]; then OPTIND=$(($OPTIND-1)); fi; break;;
- :) die "$OPTARG option is missing a required argument" ;;
- esac
-done
+subcmd_needs_package_root="1"
+if [ "$subcmd" = "clone" ]; then
+ subcmd_needs_package_root=""
+fi
-if [ "$OPTIND" -gt 1 ]; then
- shift "$(($OPTIND-1))"
+# Do some envinronment sanity checks first
+git_is_bare="$(git rev-parse --is-bare-repository 2>/dev/null)"
+if [ "$?" -eq 0 ]; then
+ if [ -z "$subcmd_needs_package_root" ]; then
+ is_valid_package_root "$PACKAGE_ROOT" ||
+ die "$subcmd should not be executed inside a valid debian packaging repository"
+ fi
+
+ if [ "$git_is_bare" = "true" ]; then
+ die "bare Git repositories are not supported."
+ fi
+
+ PACKAGE_ROOT="$(readlink -f "$(git rev-parse --git-dir)/..")"
+
+ is_valid_package_root "$PACKAGE_ROOT" ||
+ die "$PACKAGE_ROOT does NOT appear to be a valid debian packaging repository"
+
+ # Get info about debian package
+ get_debian_package_info "$PACKAGE_ROOT"
+else
+ if [ -n "$subcmd_needs_package_root" ]; then
+ die "$subcmd should be executed inside a valid debian packaging git repository"
+ fi
fi
# Execute subcommand
@@ -74,8 +174,14 @@ case "$subcmd" in
tag)
git_tag "$@"
;;
+ clone)
+ git_clone "$@"
+ ;;
+ update_config|update-config)
+ git_update_config "$@"
+ ;;
*)
- die "unsupported pkgkde-vcs Git subcommand: $subcmd"
+ die "unsupported pkgkde-vcs Git subcommand: $subcmd. Commands available: clone, tag, update-config"
;;
esac