Skip to content

Commit bcde671

Browse files
committed
feat(vcs): add verbosity argument to switching
verbosity argument to the update method allows for controlling the supression of output by commands executed from this method. The argument should be a boolean value as the `-q` flag is binary, but it now is of type int as to not require a major refactor of the base class, should other inherited classes also implement the extension of verbosity. Implements: #13329
1 parent ff1fa9a commit bcde671

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

src/pip/_internal/vcs/bazaar.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ def fetch_new(
5555
)
5656
self.run_command(cmd_args)
5757

58-
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
58+
def switch(
59+
self,
60+
dest: str,
61+
url: HiddenText,
62+
rev_options: RevOptions,
63+
verbosity: int = 0,
64+
) -> None:
5965
self.run_command(make_command("switch", url), cwd=dest)
6066

6167
def update(

src/pip/_internal/vcs/git.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,24 @@ def fetch_new(
333333
#: repo may contain submodules
334334
self.update_submodules(dest, verbosity=verbosity)
335335

336-
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
336+
def switch(
337+
self,
338+
dest: str,
339+
url: HiddenText,
340+
rev_options: RevOptions,
341+
verbosity: int = 0,
342+
) -> None:
337343
self.run_command(
338344
make_command("config", "remote.origin.url", url),
339345
cwd=dest,
340346
)
341-
cmd_args = make_command("checkout", "-q", rev_options.to_args())
347+
348+
extra_flags = []
349+
350+
if verbosity <= 0:
351+
extra_flags.append("-q")
352+
353+
cmd_args = make_command("checkout", *extra_flags, rev_options.to_args())
342354
self.run_command(cmd_args, cwd=dest)
343355

344356
self.update_submodules(dest)

src/pip/_internal/vcs/mercurial.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,20 @@ def fetch_new(
5858
cwd=dest,
5959
)
6060

61-
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
61+
def switch(
62+
self,
63+
dest: str,
64+
url: HiddenText,
65+
rev_options: RevOptions,
66+
verbosity: int = 0,
67+
) -> None:
68+
extra_flags = []
6269
repo_config = os.path.join(dest, self.dirname, "hgrc")
6370
config = configparser.RawConfigParser()
71+
72+
if verbosity <= 0:
73+
extra_flags.append("-q")
74+
6475
try:
6576
config.read(repo_config)
6677
config.set("paths", "default", url.secret)
@@ -69,7 +80,7 @@ def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
6980
except (OSError, configparser.NoSectionError) as exc:
7081
logger.warning("Could not switch Mercurial repository to %s: %s", url, exc)
7182
else:
72-
cmd_args = make_command("update", "-q", rev_options.to_args())
83+
cmd_args = make_command("update", *extra_flags, rev_options.to_args())
7384
self.run_command(cmd_args, cwd=dest)
7485

7586
def update(

src/pip/_internal/vcs/subversion.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,13 @@ def fetch_new(
300300
)
301301
self.run_command(cmd_args)
302302

303-
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
303+
def switch(
304+
self,
305+
dest: str,
306+
url: HiddenText,
307+
rev_options: RevOptions,
308+
verbosity: int = 0,
309+
) -> None:
304310
cmd_args = make_command(
305311
"switch",
306312
self.get_remote_call_options(),

src/pip/_internal/vcs/versioncontrol.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,13 @@ def fetch_new(
451451
"""
452452
raise NotImplementedError
453453

454-
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
454+
def switch(
455+
self,
456+
dest: str,
457+
url: HiddenText,
458+
rev_options: RevOptions,
459+
verbosity: int = 0,
460+
) -> None:
455461
"""
456462
Switch the repo at ``dest`` to point to ``URL``.
457463

0 commit comments

Comments
 (0)