From b6ea3bfcc398417b91a4fa5a486324f4d904b022 Mon Sep 17 00:00:00 2001 From: Ulrik Sjolin Date: Sun, 3 Jan 2010 18:20:17 +0100 Subject: Honor url.insteadOf when setting up SSH control master connection Repo can now properly handle url.insteadOf sections in the user's ~/.gitconfig file. This means that a user can now enjoy the master-ssh functionality even if he/she uses insteadOf's in ~/.gitconfig to rewrite git:// URLs to ssh:// style URLs. Change-Id: Ic0f04a9c57206a7b89eb0f10bf188c4c483debe3 Signed-off-by: Shawn O. Pearce --- git_config.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'git_config.py') diff --git a/git_config.py b/git_config.py index e1e20463..45a2d257 100644 --- a/git_config.py +++ b/git_config.py @@ -442,8 +442,30 @@ class Remote(object): self._Get('fetch', all=True)) self._review_protocol = None + def _InsteadOf(self): + globCfg = GitConfig.ForUser() + urlList = globCfg.GetSubSections('url') + longest = "" + longestUrl = "" + + for url in urlList: + key = "url." + url + ".insteadOf" + insteadOfList = globCfg.GetString(key, all=True) + + for insteadOf in insteadOfList: + if self.url.startswith(insteadOf) \ + and len(insteadOf) > len(longest): + longest = insteadOf + longestUrl = url + + if len(longest) == 0: + return self.url + + return self.url.replace(longest, longestUrl, 1) + def PreConnectFetch(self): - return _preconnect(self.url) + connectionUrl = self._InsteadOf() + return _preconnect(connectionUrl) @property def ReviewProtocol(self): -- cgit v1.2.3-54-g00ecf