From b292b98c3e9a9f666ca780ba60fdb4f306eca343 Mon Sep 17 00:00:00 2001 From: Yestin Sun Date: Mon, 2 Jul 2012 07:32:50 -0700 Subject: [PATCH] Add remote alias support in manifest The `alias` is an optional attribute in element `remote`. It can be used to override attibute `name` to be set as the remote name in each project's .git/config. Its value can be duplicated while attribute `name` has to be unique across the manifest file. This helps each project to be able to have same remote name which actually points to different remote url. It eases some automation scripts to be able to checkout/push to same remote name but actually different remote url, like: repo forall -c "git checkout -b work same_remote/work" repo forall -c "git push same_remote work:work" for example: The manifest with 'alias' will look like: ... In each project, use command "git remote -v" project1: same_alias git://git.external1.org/project1 (fetch) same_alias git://git.external1.org/project1 (push) project2: same_alias git://git.external2.org/project2 (fetch) same_alias git://git.external2.org/project2 (push) project3: same_alias ssh://git.internal.com:29418/project3 (fetch) same_alias ssh://git.internal.com:29418/project3 (push) Change-Id: I2c48263097ff107f0c978f3e83966ae71d06cb90 --- docs/manifest-format.txt | 7 +++++++ manifest_xml.py | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/manifest-format.txt b/docs/manifest-format.txt index a827f556..38868f10 100644 --- a/docs/manifest-format.txt +++ b/docs/manifest-format.txt @@ -32,6 +32,7 @@ following DTD: + @@ -89,6 +90,12 @@ name specified here is used as the remote name in each project's .git/config, and is therefore automatically available to commands like `git fetch`, `git remote`, `git pull` and `git push`. +Attribute `alias`: The alias, if specified, is used to override +`name` to be set as the remote name in each project's .git/config. +Its value can be duplicated while attribute `name` has to be unique +in the manifest file. This helps each project to be able to have +same remote name which actually points to different remote url. + Attribute `fetch`: The Git URL prefix for all projects which use this remote. Each project's name is appended to this prefix to form the actual URL used to clone the project. diff --git a/manifest_xml.py b/manifest_xml.py index 86899f63..d3156e5c 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -41,12 +41,14 @@ class _Default(object): class _XmlRemote(object): def __init__(self, name, + alias=None, fetch=None, manifestUrl=None, review=None): self.name = name self.fetchUrl = fetch self.manifestUrl = manifestUrl + self.remoteAlias = alias self.reviewUrl = review self.resolvedFetchUrl = self._resolveFetchUrl() @@ -62,7 +64,10 @@ class _XmlRemote(object): def ToRemoteSpec(self, projectName): url = self.resolvedFetchUrl.rstrip('/') + '/' + projectName - return RemoteSpec(self.name, url, self.reviewUrl) + remoteName = self.name + if self.remoteAlias: + remoteName = self.remoteAlias + return RemoteSpec(remoteName, url, self.reviewUrl) class XmlManifest(object): """manages the repo configuration file""" @@ -451,12 +456,15 @@ class XmlManifest(object): reads a element from the manifest file """ name = self._reqatt(node, 'name') + alias = node.getAttribute('alias') + if alias == '': + alias = None fetch = self._reqatt(node, 'fetch') review = node.getAttribute('review') if review == '': review = None manifestUrl = self.manifestProject.config.GetString('remote.origin.url') - return _XmlRemote(name, fetch, manifestUrl, review) + return _XmlRemote(name, alias, fetch, manifestUrl, review) def _ParseDefault(self, node): """