summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYestin Sun <sunyi0804@gmail.com>2012-07-02 07:32:50 -0700
committerShawn O. Pearce <sop@google.com>2012-07-31 22:13:13 -0700
commitb292b98c3e9a9f666ca780ba60fdb4f306eca343 (patch)
tree75cea727be50c2e5b86d5c0fa62baae379315bf7
parent2f127de7520a0b689bfe5082360eeb53a05d6e2d (diff)
downloadgit-repo-b292b98c3e9a9f666ca780ba60fdb4f306eca343.tar.gz
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: <?xml version='1.0' encoding='UTF-8'?> <manifest> <remote alias="same_alias" fetch="git://git.external1.org/" name="ext1" review="http://review.external1.org"/> <remote alias="same_alias" fetch="git://git.external2.org/" name="ext2" review="http://review.external2.org"/> <remote alias="same_alias" fetch="ssh://git.internal.com:29418" name="int" review="http://review.internal.com"/> <default remote="int" revision="int-branch" sync-j="2"/> <project name="path/to/project1" path="project1" remote="ext1"/> <project name="path/to/project2" path="project2" remote="ext2"/> <project name="path/to/project3" path="project3"/> ... </manifest> 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
-rw-r--r--docs/manifest-format.txt7
-rw-r--r--manifest_xml.py12
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:
32 32
33 <!ELEMENT remote (EMPTY)> 33 <!ELEMENT remote (EMPTY)>
34 <!ATTLIST remote name ID #REQUIRED> 34 <!ATTLIST remote name ID #REQUIRED>
35 <!ATTLIST remote alias CDATA #IMPLIED>
35 <!ATTLIST remote fetch CDATA #REQUIRED> 36 <!ATTLIST remote fetch CDATA #REQUIRED>
36 <!ATTLIST remote review CDATA #IMPLIED> 37 <!ATTLIST remote review CDATA #IMPLIED>
37 38
@@ -89,6 +90,12 @@ name specified here is used as the remote name in each project's
89.git/config, and is therefore automatically available to commands 90.git/config, and is therefore automatically available to commands
90like `git fetch`, `git remote`, `git pull` and `git push`. 91like `git fetch`, `git remote`, `git pull` and `git push`.
91 92
93Attribute `alias`: The alias, if specified, is used to override
94`name` to be set as the remote name in each project's .git/config.
95Its value can be duplicated while attribute `name` has to be unique
96in the manifest file. This helps each project to be able to have
97same remote name which actually points to different remote url.
98
92Attribute `fetch`: The Git URL prefix for all projects which use 99Attribute `fetch`: The Git URL prefix for all projects which use
93this remote. Each project's name is appended to this prefix to 100this remote. Each project's name is appended to this prefix to
94form the actual URL used to clone the project. 101form 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):
41class _XmlRemote(object): 41class _XmlRemote(object):
42 def __init__(self, 42 def __init__(self,
43 name, 43 name,
44 alias=None,
44 fetch=None, 45 fetch=None,
45 manifestUrl=None, 46 manifestUrl=None,
46 review=None): 47 review=None):
47 self.name = name 48 self.name = name
48 self.fetchUrl = fetch 49 self.fetchUrl = fetch
49 self.manifestUrl = manifestUrl 50 self.manifestUrl = manifestUrl
51 self.remoteAlias = alias
50 self.reviewUrl = review 52 self.reviewUrl = review
51 self.resolvedFetchUrl = self._resolveFetchUrl() 53 self.resolvedFetchUrl = self._resolveFetchUrl()
52 54
@@ -62,7 +64,10 @@ class _XmlRemote(object):
62 64
63 def ToRemoteSpec(self, projectName): 65 def ToRemoteSpec(self, projectName):
64 url = self.resolvedFetchUrl.rstrip('/') + '/' + projectName 66 url = self.resolvedFetchUrl.rstrip('/') + '/' + projectName
65 return RemoteSpec(self.name, url, self.reviewUrl) 67 remoteName = self.name
68 if self.remoteAlias:
69 remoteName = self.remoteAlias
70 return RemoteSpec(remoteName, url, self.reviewUrl)
66 71
67class XmlManifest(object): 72class XmlManifest(object):
68 """manages the repo configuration file""" 73 """manages the repo configuration file"""
@@ -451,12 +456,15 @@ class XmlManifest(object):
451 reads a <remote> element from the manifest file 456 reads a <remote> element from the manifest file
452 """ 457 """
453 name = self._reqatt(node, 'name') 458 name = self._reqatt(node, 'name')
459 alias = node.getAttribute('alias')
460 if alias == '':
461 alias = None
454 fetch = self._reqatt(node, 'fetch') 462 fetch = self._reqatt(node, 'fetch')
455 review = node.getAttribute('review') 463 review = node.getAttribute('review')
456 if review == '': 464 if review == '':
457 review = None 465 review = None
458 manifestUrl = self.manifestProject.config.GetString('remote.origin.url') 466 manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
459 return _XmlRemote(name, fetch, manifestUrl, review) 467 return _XmlRemote(name, alias, fetch, manifestUrl, review)
460 468
461 def _ParseDefault(self, node): 469 def _ParseDefault(self, node):
462 """ 470 """