| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ Contributors are: | |||
| 19 | 19 | -Timothy B. Hartman <tbhartman _at_ gmail.com> | |
| 20 | 20 | -Konstantin Popov <konstantin.popov.89 _at_ yandex.ru> | |
| 21 | 21 | -Peter Jones <pjones _at_ redhat.com> | |
| 22 | + -Anson Mansfield <anson.mansfield _at_ gmail.com> | ||
| 22 | 23 | -Ken Odegard <ken.odegard _at_ gmail.com> | |
| 23 | 24 | -Alexis Horgix Chotard | |
| 24 | 25 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,7 +47,7 @@ | |||
| 47 | 47 | execute_kwargs = set(('istream', 'with_extended_output', | |
| 48 | 48 | 'with_exceptions', 'as_process', 'stdout_as_string', | |
| 49 | 49 | 'output_stream', 'with_stdout', 'kill_after_timeout', | |
| 50 | - 'universal_newlines', 'shell')) | ||
| 50 | + 'universal_newlines', 'shell', 'env')) | ||
| 51 | 51 | ||
| 52 | 52 | log = logging.getLogger(__name__) | |
| 53 | 53 | log.addHandler(logging.NullHandler()) | |
@@ -597,6 +597,7 @@ def execute(self, command, | |||
| 597 | 597 | with_stdout=True, | |
| 598 | 598 | universal_newlines=False, | |
| 599 | 599 | shell=None, | |
| 600 | + env=None, | ||
| 600 | 601 | **subprocess_kwargs | |
| 601 | 602 | ): | |
| 602 | 603 | """Handles executing the command on the shell and consumes and returns | |
@@ -640,6 +641,9 @@ def execute(self, command, | |||
| 640 | 641 | decoded into a string using the default encoding (usually utf-8). | |
| 641 | 642 | The latter can fail, if the output contains binary data. | |
| 642 | 643 | ||
| 644 | + :param env: | ||
| 645 | + A dictionary of environment variables to be passed to `subprocess.Popen`. | ||
| 646 | + | ||
| 643 | 647 | :param subprocess_kwargs: | |
| 644 | 648 | Keyword arguments to be passed to subprocess.Popen. Please note that | |
| 645 | 649 | some of the valid kwargs are already set by this method, the ones you | |
@@ -685,6 +689,7 @@ def execute(self, command, | |||
| 685 | 689 | cwd = self._working_dir or os.getcwd() | |
| 686 | 690 | ||
| 687 | 691 | # Start the process | |
| 692 | + inline_env = env | ||
| 688 | 693 | env = os.environ.copy() | |
| 689 | 694 | # Attempt to force all output to plain ascii english, which is what some parsing code | |
| 690 | 695 | # may expect. | |
@@ -693,6 +698,8 @@ def execute(self, command, | |||
| 693 | 698 | env["LANGUAGE"] = "C" | |
| 694 | 699 | env["LC_ALL"] = "C" | |
| 695 | 700 | env.update(self._environment) | |
| 701 | + if inline_env is not None: | ||
| 702 | + env.update(inline_env) | ||
| 696 | 703 | ||
| 697 | 704 | if is_win: | |
| 698 | 705 | cmd_not_found_exception = OSError | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,6 +106,21 @@ def test_it_ignores_false_kwargs(self, git): | |||
| 106 | 106 | self.git.version(pass_this_kwarg=False) | |
| 107 | 107 | assert_true("pass_this_kwarg" not in git.call_args[1]) | |
| 108 | 108 | ||
| 109 | + def test_it_accepts_environment_variables(self): | ||
| 110 | + filename = fixture_path("ls_tree_empty") | ||
| 111 | + with open(filename, 'r') as fh: | ||
| 112 | + tree = self.git.mktree(istream=fh) | ||
| 113 | + env = { | ||
| 114 | + 'GIT_AUTHOR_NAME': 'Author Name', | ||
| 115 | + 'GIT_AUTHOR_EMAIL': 'author@example.com', | ||
| 116 | + 'GIT_AUTHOR_DATE': '1400000000+0000', | ||
| 117 | + 'GIT_COMMITTER_NAME': 'Committer Name', | ||
| 118 | + 'GIT_COMMITTER_EMAIL': 'committer@example.com', | ||
| 119 | + 'GIT_COMMITTER_DATE': '1500000000+0000', | ||
| 120 | + } | ||
| 121 | + commit = self.git.commit_tree(tree, m='message', env=env) | ||
| 122 | + assert_equal(commit, '4cfd6b0314682d5a58f80be39850bad1640e9241') | ||
| 123 | + | ||
| 109 | 124 | def test_persistent_cat_file_command(self): | |
| 110 | 125 | # read header only | |
| 111 | 126 | import subprocess as sp | |
| Back | FazBrowse Home | New Git URL |
0 commit comments