| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ | |||
| 11 | 11 | from git_python.stats import Stats | |
| 12 | 12 | from git_python.tag import Tag | |
| 13 | 13 | from git_python.tree import Tree | |
| 14 | - from git_python.utils import shell_escape, dashify, touch | ||
| 14 | + from git_python.utils import dashify, touch | ||
| 15 | 15 | ||
| 16 | 16 | __all__ = [ name for name, obj in locals().items() | |
| 17 | 17 | if not (name.startswith('_') or inspect.ismodule(obj)) ] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,27 +11,27 @@ class Git(MethodMissingMixin): | |||
| 11 | 11 | def __init__(self, git_dir): | |
| 12 | 12 | super(Git, self).__init__() | |
| 13 | 13 | self.git_dir = git_dir | |
| 14 | - | ||
| 15 | - git_binary = "/usr/bin/env git" | ||
| 16 | - | ||
| 14 | + | ||
| 17 | 15 | @property | |
| 18 | 16 | def get_dir(self): | |
| 19 | 17 | return self.git_dir | |
| 20 | - | ||
| 18 | + | ||
| 21 | 19 | def execute(self, command): | |
| 22 | 20 | """ | |
| 23 | 21 | Handles executing the command on the shell and consumes and returns | |
| 24 | 22 | the returned information (stdout) | |
| 25 | - | ||
| 23 | + | ||
| 26 | 24 | ``command`` | |
| 27 | 25 | The command to execute | |
| 28 | 26 | """ | |
| 29 | - print command | ||
| 30 | - proc = subprocess.Popen(command, | ||
| 31 | - shell=True, | ||
| 32 | - stdout=subprocess.PIPE | ||
| 27 | + print ' '.join(command) | ||
| 28 | + proc = subprocess.Popen(command, | ||
| 29 | + cwd = self.git_dir, | ||
| 30 | + stdout=subprocess.PIPE | ||
| 33 | 31 | ) | |
| 34 | - stdout_value = proc.communicate()[0] | ||
| 32 | + proc.wait() | ||
| 33 | + stdout_value = proc.stdout.read() | ||
| 34 | + proc.stdout.close() | ||
| 35 | 35 | return stdout_value | |
| 36 | 36 | ||
| 37 | 37 | def transform_kwargs(self, **kwargs): | |
@@ -44,38 +44,41 @@ def transform_kwargs(self, **kwargs): | |||
| 44 | 44 | if v is True: | |
| 45 | 45 | args.append("-%s" % k) | |
| 46 | 46 | else: | |
| 47 | - args.append("-%s %r" % (k, v)) | ||
| 47 | + args.append("-%s" % k) | ||
| 48 | + args.append(v) | ||
| 48 | 49 | else: | |
| 49 | 50 | if v is True: | |
| 50 | 51 | args.append("--%s" % dashify(k)) | |
| 51 | 52 | else: | |
| 52 | - args.append("--%s=%r" % (dashify(k), v)) | ||
| 53 | + args.append("--%s=%s" % (dashify(k), v)) | ||
| 53 | 54 | return args | |
| 54 | - | ||
| 55 | + | ||
| 55 | 56 | def method_missing(self, method, *args, **kwargs): | |
| 56 | 57 | """ | |
| 57 | 58 | Run the given git command with the specified arguments and return | |
| 58 | 59 | the result as a String | |
| 59 | - | ||
| 60 | + | ||
| 60 | 61 | ``method`` | |
| 61 | 62 | is the command | |
| 62 | - | ||
| 63 | + | ||
| 63 | 64 | ``args`` | |
| 64 | 65 | is the list of arguments | |
| 65 | - | ||
| 66 | + | ||
| 66 | 67 | ``kwargs`` | |
| 67 | 68 | is a dict of keyword arguments | |
| 68 | 69 | ||
| 69 | 70 | Examples | |
| 70 | 71 | git.rev_list('master', max_count=10, header=True) | |
| 71 | - | ||
| 72 | + | ||
| 72 | 73 | Returns | |
| 73 | 74 | str | |
| 74 | 75 | """ | |
| 75 | 76 | opt_args = self.transform_kwargs(**kwargs) | |
| 76 | - ext_args = map(lambda a: (a == '--') and a or "%s" % shell_escape(a), args) | ||
| 77 | + ext_args = map(lambda a: (a == '--') and a or "%s" % a, args) | ||
| 77 | 78 | args = opt_args + ext_args | |
| 78 | - | ||
| 79 | - call = "%s --git-dir=%s %s %s" % (self.git_binary, self.git_dir, dashify(method), ' '.join(args)) | ||
| 79 | + | ||
| 80 | + call = ['git-'+dashify(method)] | ||
| 81 | + call.extend(args) | ||
| 82 | + | ||
| 80 | 83 | stdout_value = self.execute(call) | |
| 81 | 84 | return stdout_value | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,3 @@ | |||
| 1 | - def shell_escape(string): | ||
| 2 | - return str(string).replace("'", "\\\\'") | ||
| 3 | - | ||
| 4 | 1 | def dashify(string): | |
| 5 | 2 | return string.replace('_', '-') | |
| 6 | 3 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,9 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | 5 | class TestGit(object): | |
| 6 | 6 | def setup(self): | |
| 7 | - base = os.path.join(os.path.dirname(__file__), "../.."), | ||
| 7 | + base = os.path.join(os.path.dirname(__file__), "../..") | ||
| 8 | 8 | self.git = Git(base) | |
| 9 | - self.git_bin_base = "%s --git-dir=%s" % (Git.git_binary, base) | ||
| 10 | 9 | ||
| 11 | 10 | @patch(Git, 'execute') | |
| 12 | 11 | def test_method_missing_calls_execute(self, git): | |
@@ -17,31 +16,12 @@ def test_method_missing_calls_execute(self, git): | |||
| 17 | 16 | ||
| 18 | 17 | def test_it_transforms_kwargs_into_git_command_arguments(self): | |
| 19 | 18 | assert_equal(["-s"], self.git.transform_kwargs(**{'s': True})) | |
| 20 | - assert_equal(["-s 5"], self.git.transform_kwargs(**{'s': 5})) | ||
| 19 | + assert_equal(["-s", 5], self.git.transform_kwargs(**{'s': 5})) | ||
| 21 | 20 | ||
| 22 | 21 | assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True})) | |
| 23 | 22 | assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5})) | |
| 24 | 23 | ||
| 25 | 24 | assert_equal(["-s", "-t"], self.git.transform_kwargs(**{'s': True, 't': True})) | |
| 26 | 25 | ||
| 27 | 26 | def test_it_executes_git_to_shell_and_returns_result(self): | |
| 28 | - assert_match('^git version [\d\.]*$', self.git.execute("%s version" % Git.git_binary)) | ||
| 29 | - | ||
| 30 | - def test_it_transforms_kwargs_shell_escapes_arguments(self): | ||
| 31 | - assert_equal(["--foo=\"bazz'er\""], self.git.transform_kwargs(**{'foo': "bazz'er"})) | ||
| 32 | - assert_equal(["-x \"bazz'er\""], self.git.transform_kwargs(**{'x': "bazz'er"})) | ||
| 33 | - | ||
| 34 | - @patch(Git, 'execute') | ||
| 35 | - def test_it_really_shell_escapes_arguments_to_the_git_shell_1(self, git): | ||
| 36 | - self.git.foo(**{'bar': "bazz'er"}) | ||
| 37 | - assert_true(git.called) | ||
| 38 | - assert_equal(git.call_args, ((("%s foo --bar=\"bazz'er\"" % self.git_bin_base),), {})) | ||
| 39 | - | ||
| 40 | - @patch(Git, 'execute') | ||
| 41 | - def test_it_really_shell_escapes_arguments_to_the_git_shell_2(self, git): | ||
| 42 | - self.git.bar(**{'x': "quu'x"}) | ||
| 43 | - assert_true(git.called) | ||
| 44 | - assert_equal(git.call_args, ((("%s bar -x \"quu'x\"" % self.git_bin_base),), {})) | ||
| 45 | - | ||
| 46 | - def test_it_shell_escapes_the_standalone_argument(self): | ||
| 47 | - self.git.foo("bar's", {}) | ||
| 27 | + assert_match('^git version [\d\.]*$', self.git.execute(["git","version"])) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ def test_new_should_raise_on_invalid_repo_location(self): | |||
| 13 | 13 | ||
| 14 | 14 | @raises(NoSuchPathError) | |
| 15 | 15 | def test_new_should_raise_on_non_existant_path(self): | |
| 16 | - Repo("/foobar") | ||
| 16 | + Repo("~/foobar") | ||
| 17 | 17 | ||
| 18 | 18 | def test_description(self): | |
| 19 | 19 | assert_equal("Unnamed repository; edit this file to name it for gitweb.", self.repo.description) | |
@@ -108,45 +108,45 @@ def test_blob(self, git): | |||
| 108 | 108 | def test_init_bare(self, repo, git): | |
| 109 | 109 | git.return_value = True | |
| 110 | 110 | ||
| 111 | - Repo.init_bare("/foo/bar.git") | ||
| 111 | + Repo.init_bare("~/foo/bar.git") | ||
| 112 | 112 | ||
| 113 | 113 | assert_true(git.called) | |
| 114 | 114 | assert_equal(git.call_args, (('init',), {})) | |
| 115 | 115 | assert_true(repo.called) | |
| 116 | - assert_equal(repo.call_args, (('/foo/bar.git',), {})) | ||
| 116 | + assert_equal(repo.call_args, (('~/foo/bar.git',), {})) | ||
| 117 | 117 | ||
| 118 | 118 | @patch(Repo, '__init__') | |
| 119 | 119 | @patch(Git, 'method_missing') | |
| 120 | 120 | def test_init_bare_with_options(self, repo, git): | |
| 121 | 121 | git.return_value = True | |
| 122 | 122 | ||
| 123 | - Repo.init_bare("/foo/bar.git", **{'template': "/baz/sweet"}) | ||
| 123 | + Repo.init_bare("~/foo/bar.git", **{'template': "/baz/sweet"}) | ||
| 124 | 124 | ||
| 125 | 125 | assert_true(git.called) | |
| 126 | 126 | assert_equal(git.call_args, (('init',), {'template': '/baz/sweet'})) | |
| 127 | 127 | assert_true(repo.called) | |
| 128 | - assert_equal(repo.call_args, (('/foo/bar.git',), {})) | ||
| 128 | + assert_equal(repo.call_args, (('~/foo/bar.git',), {})) | ||
| 129 | 129 | ||
| 130 | 130 | @patch(Repo, '__init__') | |
| 131 | 131 | @patch(Git, 'method_missing') | |
| 132 | 132 | def test_fork_bare(self, repo, git): | |
| 133 | 133 | git.return_value = None | |
| 134 | 134 | ||
| 135 | - self.repo.fork_bare("/foo/bar.git") | ||
| 135 | + self.repo.fork_bare("~/foo/bar.git") | ||
| 136 | 136 | ||
| 137 | 137 | assert_true(git.called) | |
| 138 | - assert_equal(git.call_args, (('clone', '%s/.git' % absolute_project_path(), '/foo/bar.git'), {'bare': True})) | ||
| 138 | + assert_equal(git.call_args, (('clone', '%s/.git' % absolute_project_path(), '~/foo/bar.git'), {'bare': True})) | ||
| 139 | 139 | assert_true(repo.called) | |
| 140 | 140 | ||
| 141 | 141 | @patch(Repo, '__init__') | |
| 142 | 142 | @patch(Git, 'method_missing') | |
| 143 | 143 | def test_fork_bare_with_options(self, repo, git): | |
| 144 | 144 | git.return_value = None | |
| 145 | 145 | ||
| 146 | - self.repo.fork_bare("/foo/bar.git", **{'template': '/awesome'}) | ||
| 146 | + self.repo.fork_bare("~/foo/bar.git", **{'template': '/awesome'}) | ||
| 147 | 147 | ||
| 148 | 148 | assert_true(git.called) | |
| 149 | - assert_equal(git.call_args, (('clone', '%s/.git' % absolute_project_path(), '/foo/bar.git'), | ||
| 149 | + assert_equal(git.call_args, (('clone', '%s/.git' % absolute_project_path(), '~/foo/bar.git'), | ||
| 150 | 150 | {'bare': True, 'template': '/awesome'})) | |
| 151 | 151 | assert_true(repo.called) | |
| 152 | 152 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,10 +6,10 @@ class TestUtils(object): | |||
| 6 | 6 | def setup(self): | |
| 7 | 7 | base = os.path.join(os.path.dirname(__file__), "../.."), | |
| 8 | 8 | self.git = Git(base) | |
| 9 | - self.git_bin_base = "%s --git-dir='%s'" % (Git.git_binary, base) | ||
| 9 | + # self.git_bin_base = "%s --git-dir='%s'" % (Git.git_binary, base) | ||
| 10 | 10 | ||
| 11 | - def test_it_escapes_single_quotes_with_shell_escape(self): | ||
| 12 | - assert_equal("\\\\'foo", shell_escape("'foo")) | ||
| 11 | + # def test_it_escapes_single_quotes_with_shell_escape(self): | ||
| 12 | + # assert_equal("\\\\'foo", shell_escape("'foo")) | ||
| 13 | 13 | ||
| 14 | 14 | def test_it_should_dashify(self): | |
| 15 | 15 | assert_equal('this-is-my-argument', dashify('this_is_my_argument')) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments