##// END OF EJS Templates
fetch: hide authentication details
Bryan O'Sullivan -
r5798:86f5d8f6 default
parent child Browse files
Show More
@@ -43,7 +43,8 b" def fetch(ui, repo, source='default', **"
43 if not err:
43 if not err:
44 mod, add, rem = repo.status()[:3]
44 mod, add, rem = repo.status()[:3]
45 message = (cmdutil.logmessage(opts) or
45 message = (cmdutil.logmessage(opts) or
46 (_('Automated merge with %s') % other.url()))
46 (_('Automated merge with %s') %
47 util.removeauth(other.url())))
47 n = repo.commit(mod + add + rem, message,
48 n = repo.commit(mod + add + rem, message,
48 opts['user'], opts['date'],
49 opts['user'], opts['date'],
49 force_editor=opts.get('force_editor'))
50 force_editor=opts.get('force_editor'))
@@ -54,7 +55,8 b" def fetch(ui, repo, source='default', **"
54 cmdutil.setremoteconfig(ui, opts)
55 cmdutil.setremoteconfig(ui, opts)
55
56
56 other = hg.repository(ui, ui.expandpath(source))
57 other = hg.repository(ui, ui.expandpath(source))
57 ui.status(_('pulling from %s\n') % ui.expandpath(source))
58 ui.status(_('pulling from %s\n') %
59 util.hidepassword(ui.expandpath(source)))
58 revs = None
60 revs = None
59 if opts['rev'] and not other.local():
61 if opts['rev'] and not other.local():
60 raise util.Abort(_("fetch -r doesn't work for remote repositories yet"))
62 raise util.Abort(_("fetch -r doesn't work for remote repositories yet"))
@@ -1707,32 +1707,14 b' def uirepr(s):'
1707 # Avoid double backslash in Windows path repr()
1707 # Avoid double backslash in Windows path repr()
1708 return repr(s).replace('\\\\', '\\')
1708 return repr(s).replace('\\\\', '\\')
1709
1709
1710 def hidepassword(url):
1710 def hidepassword(url, user=True, password=True):
1711 '''replaces the password in the url string by three asterisks (***)
1711 '''hide user credential in a url string'''
1712 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
1713 netloc = re.sub('([^:]*):([^@]*)@(.*)', r'\1:***@\3', netloc)
1714 return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
1712
1715
1713 >>> hidepassword('http://www.example.com/some/path#fragment')
1716 def removeauth(url):
1714 'http://www.example.com/some/path#fragment'
1717 '''remove all authentication information from a url string'''
1715 >>> hidepassword('http://me@www.example.com/some/path#fragment')
1718 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
1716 'http://me@www.example.com/some/path#fragment'
1719 netloc = netloc[netloc.find('@')+1:]
1717 >>> hidepassword('http://me:simplepw@www.example.com/path#frag')
1720 return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
1718 'http://me:***@www.example.com/path#frag'
1719 >>> hidepassword('http://me:complex:pw@www.example.com/path#frag')
1720 'http://me:***@www.example.com/path#frag'
1721 >>> hidepassword('/path/to/repo')
1722 '/path/to/repo'
1723 >>> hidepassword('relative/path/to/repo')
1724 'relative/path/to/repo'
1725 >>> hidepassword('c:\\\\path\\\\to\\\\repo')
1726 'c:\\\\path\\\\to\\\\repo'
1727 >>> hidepassword('c:/path/to/repo')
1728 'c:/path/to/repo'
1729 >>> hidepassword('bundle://path/to/bundle')
1730 'bundle://path/to/bundle'
1731 '''
1732 url_parts = list(urlparse.urlparse(url))
1733 host_with_pw_pattern = re.compile('^([^:]*):([^@]*)@(.*)$')
1734 if host_with_pw_pattern.match(url_parts[1]):
1735 url_parts[1] = re.sub(host_with_pw_pattern, r'\1:***@\3',
1736 url_parts[1])
1737 return urlparse.urlunparse(url_parts)
1738
@@ -20,5 +20,20 b' hg --cwd b parents -q'
20
20
21 echo c > c/c
21 echo c > c/c
22 hg --cwd c commit -d '3 0' -Amc
22 hg --cwd c commit -d '3 0' -Amc
23
24 hg clone c d
25 hg clone c e
26
23 hg --cwd c fetch -d '4 0' -m 'automated merge' ../a
27 hg --cwd c fetch -d '4 0' -m 'automated merge' ../a
24 ls c
28 ls c
29
30 hg --cwd a serve -a localhost -p $HGPORT -d --pid-file=hg.pid
31 cat a/hg.pid >> "$DAEMON_PIDS"
32
33 echo '% fetch over http, no auth'
34 hg --cwd d fetch -d '5 0' http://localhost:$HGPORT/
35 hg --cwd d tip --template '{desc}\n'
36
37 echo '% fetch over http with auth (should be hidden in desc)'
38 hg --cwd e fetch -d '5 0' http://user:password@localhost:$HGPORT/
39 hg --cwd e tip --template '{desc}\n'
@@ -13,6 +13,8 b' added 1 changesets with 1 changes to 1 f'
13 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
13 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
14 1:97d72e5f12c7
14 1:97d72e5f12c7
15 adding c
15 adding c
16 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
17 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
16 pulling from ../a
18 pulling from ../a
17 searching for changes
19 searching for changes
18 adding changesets
20 adding changesets
@@ -25,3 +27,25 b' new changeset 3:cd3a41621cf0 merges remo'
25 a
27 a
26 b
28 b
27 c
29 c
30 % fetch over http, no auth
31 pulling from http://localhost:20059/
32 searching for changes
33 adding changesets
34 adding manifests
35 adding file changes
36 added 1 changesets with 1 changes to 1 files (+1 heads)
37 merging with new head 2:97d72e5f12c7
38 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
39 new changeset 3:0b6439e938f9 merges remote changes with local
40 Automated merge with http://localhost:20059/
41 % fetch over http with auth (should be hidden in desc)
42 pulling from http://user:***@localhost:20059/
43 searching for changes
44 adding changesets
45 adding manifests
46 adding file changes
47 added 1 changesets with 1 changes to 1 files (+1 heads)
48 merging with new head 2:97d72e5f12c7
49 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
50 new changeset 3:0b6439e938f9 merges remote changes with local
51 Automated merge with http://localhost:20059/
General Comments 0
You need to be logged in to leave comments. Login now