Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make VersionControl.fetch_new() an instance method #6519

Merged
merged 1 commit into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/pip/_internal/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ def compare_urls(cls, url1, url2):
"""
return (cls.normalize_url(url1) == cls.normalize_url(url2))

@classmethod
def fetch_new(cls, dest, url, rev_options):
def fetch_new(self, dest, url, rev_options):
"""
Fetch a revision from a repository, in the case that this is the
first fetch from the repository.
Expand Down
5 changes: 2 additions & 3 deletions src/pip/_internal/vcs/bazaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def export(self, location, url):
show_stdout=False,
)

@classmethod
def fetch_new(cls, dest, url, rev_options):
def fetch_new(self, dest, url, rev_options):
rev_display = rev_options.to_display()
logger.info(
'Checking out %s%s to %s',
Expand All @@ -56,7 +55,7 @@ def fetch_new(cls, dest, url, rev_options):
display_path(dest),
)
cmd_args = ['branch', '-q'] + rev_options.to_args() + [url, dest]
cls.run_command(cmd_args)
self.run_command(cmd_args)

def switch(self, dest, url, rev_options):
self.run_command(['switch', url], cwd=dest)
Expand Down
17 changes: 8 additions & 9 deletions src/pip/_internal/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,36 +180,35 @@ def is_commit_id_equal(cls, dest, name):

return cls.get_revision(dest) == name

@classmethod
def fetch_new(cls, dest, url, rev_options):
def fetch_new(self, dest, url, rev_options):
rev_display = rev_options.to_display()
logger.info(
'Cloning %s%s to %s', redact_password_from_url(url),
rev_display, display_path(dest),
)
cls.run_command(['clone', '-q', url, dest])
self.run_command(['clone', '-q', url, dest])

if rev_options.rev:
# Then a specific revision was requested.
rev_options = cls.resolve_revision(dest, url, rev_options)
rev_options = self.resolve_revision(dest, url, rev_options)
branch_name = getattr(rev_options, 'branch_name', None)
if branch_name is None:
# Only do a checkout if the current commit id doesn't match
# the requested revision.
if not cls.is_commit_id_equal(dest, rev_options.rev):
if not self.is_commit_id_equal(dest, rev_options.rev):
cmd_args = ['checkout', '-q'] + rev_options.to_args()
cls.run_command(cmd_args, cwd=dest)
elif cls.get_current_branch(dest) != branch_name:
self.run_command(cmd_args, cwd=dest)
elif self.get_current_branch(dest) != branch_name:
# Then a specific branch was requested, and that branch
# is not yet checked out.
track_branch = 'origin/{}'.format(branch_name)
cmd_args = [
'checkout', '-b', branch_name, '--track', track_branch,
]
cls.run_command(cmd_args, cwd=dest)
self.run_command(cmd_args, cwd=dest)

#: repo may contain submodules
cls.update_submodules(dest)
self.update_submodules(dest)

def switch(self, dest, url, rev_options):
self.run_command(['config', 'remote.origin.url', url], cwd=dest)
Expand Down
7 changes: 3 additions & 4 deletions src/pip/_internal/vcs/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ def export(self, location, url):
['archive', location], show_stdout=False, cwd=temp_dir.path
)

@classmethod
def fetch_new(cls, dest, url, rev_options):
def fetch_new(self, dest, url, rev_options):
rev_display = rev_options.to_display()
logger.info(
'Cloning hg %s%s to %s',
url,
rev_display,
display_path(dest),
)
cls.run_command(['clone', '--noupdate', '-q', url, dest])
self.run_command(['clone', '--noupdate', '-q', url, dest])
cmd_args = ['update', '-q'] + rev_options.to_args()
cls.run_command(cmd_args, cwd=dest)
self.run_command(cmd_args, cwd=dest)

def switch(self, dest, url, rev_options):
repo_config = os.path.join(dest, self.dirname, 'hgrc')
Expand Down
5 changes: 2 additions & 3 deletions src/pip/_internal/vcs/subversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def export(self, location, url):
cmd_args = ['export'] + rev_options.to_args() + [url, location]
self.run_command(cmd_args, show_stdout=False)

@classmethod
def fetch_new(cls, dest, url, rev_options):
def fetch_new(self, dest, url, rev_options):
rev_display = rev_options.to_display()
logger.info(
'Checking out %s%s to %s',
Expand All @@ -61,7 +60,7 @@ def fetch_new(cls, dest, url, rev_options):
display_path(dest),
)
cmd_args = ['checkout', '-q'] + rev_options.to_args() + [url, dest]
cls.run_command(cmd_args)
self.run_command(cmd_args)

def switch(self, dest, url, rev_options):
cmd_args = ['switch'] + rev_options.to_args() + [url, dest]
Expand Down