From 9b975d9fcf5924800f9ea5d68d7d79f743ca9af7 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Tue, 20 May 2008 22:27:42 +0200 Subject: removed some more spaces --- lib/git_python/git.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/git_python/git.py b/lib/git_python/git.py index ee256356..2251ecb2 100644 --- a/lib/git_python/git.py +++ b/lib/git_python/git.py @@ -11,25 +11,25 @@ class Git(MethodMissingMixin): def __init__(self, git_dir): super(Git, self).__init__() self.git_dir = git_dir - + git_binary = "/usr/bin/env git" - + @property def get_dir(self): return self.git_dir - + def execute(self, command): """ Handles executing the command on the shell and consumes and returns the returned information (stdout) - + ``command`` The command to execute """ print command - proc = subprocess.Popen(command, + proc = subprocess.Popen(command, shell=True, - stdout=subprocess.PIPE + stdout=subprocess.PIPE ) stdout_value = proc.communicate()[0] return stdout_value @@ -51,31 +51,31 @@ class Git(MethodMissingMixin): else: args.append("--%s=%r" % (dashify(k), v)) return args - + def method_missing(self, method, *args, **kwargs): """ Run the given git command with the specified arguments and return the result as a String - + ``method`` is the command - + ``args`` is the list of arguments - + ``kwargs`` is a dict of keyword arguments Examples git.rev_list('master', max_count=10, header=True) - + Returns str """ opt_args = self.transform_kwargs(**kwargs) ext_args = map(lambda a: (a == '--') and a or "%s" % shell_escape(a), args) args = opt_args + ext_args - + call = "%s --git-dir=%s %s %s" % (self.git_binary, self.git_dir, dashify(method), ' '.join(args)) stdout_value = self.execute(call) return stdout_value -- cgit v1.2.3 From ae54e18d7ca7bc8b8fbc667119fb60b25f0f3871 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Tue, 20 May 2008 23:26:06 +0200 Subject: made subprocess not use a shell... --- lib/git_python/__init__.py | 2 +- lib/git_python/git.py | 20 +++++++++++--------- lib/git_python/utils.py | 3 --- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/git_python/__init__.py b/lib/git_python/__init__.py index 71142a40..11f93313 100644 --- a/lib/git_python/__init__.py +++ b/lib/git_python/__init__.py @@ -11,7 +11,7 @@ from git_python.repo import Repo from git_python.stats import Stats from git_python.tag import Tag from git_python.tree import Tree -from git_python.utils import shell_escape, dashify, touch +from git_python.utils import dashify, touch __all__ = [ name for name, obj in locals().items() if not (name.startswith('_') or inspect.ismodule(obj)) ] diff --git a/lib/git_python/git.py b/lib/git_python/git.py index 2251ecb2..25cd1cce 100644 --- a/lib/git_python/git.py +++ b/lib/git_python/git.py @@ -12,8 +12,6 @@ class Git(MethodMissingMixin): super(Git, self).__init__() self.git_dir = git_dir - git_binary = "/usr/bin/env git" - @property def get_dir(self): return self.git_dir @@ -26,12 +24,14 @@ class Git(MethodMissingMixin): ``command`` The command to execute """ - print command + print ' '.join(command) proc = subprocess.Popen(command, - shell=True, + cwd = self.git_dir, stdout=subprocess.PIPE ) - stdout_value = proc.communicate()[0] + proc.wait() + stdout_value = proc.stdout.read() + proc.stdout.close() return stdout_value def transform_kwargs(self, **kwargs): @@ -44,12 +44,13 @@ class Git(MethodMissingMixin): if v is True: args.append("-%s" % k) else: - args.append("-%s %r" % (k, v)) + args.append("-%s" % k) + args.append(v) else: if v is True: args.append("--%s" % dashify(k)) else: - args.append("--%s=%r" % (dashify(k), v)) + args.append("--%s=%s" % (dashify(k), v)) return args def method_missing(self, method, *args, **kwargs): @@ -73,9 +74,10 @@ class Git(MethodMissingMixin): str """ opt_args = self.transform_kwargs(**kwargs) - ext_args = map(lambda a: (a == '--') and a or "%s" % shell_escape(a), args) + ext_args = map(lambda a: (a == '--') and a or "%s" % a, args) args = opt_args + ext_args - call = "%s --git-dir=%s %s %s" % (self.git_binary, self.git_dir, dashify(method), ' '.join(args)) + call = ['git-'+dashify(method)] + call.extend(args) stdout_value = self.execute(call) return stdout_value diff --git a/lib/git_python/utils.py b/lib/git_python/utils.py index 2bd6f2cd..c2140ba0 100644 --- a/lib/git_python/utils.py +++ b/lib/git_python/utils.py @@ -1,6 +1,3 @@ -def shell_escape(string): - return str(string).replace("'", "\\\\'") - def dashify(string): return string.replace('_', '-') -- cgit v1.2.3 From 30472cf3132b8c03e528b23d1c7533de740e28ab Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Tue, 20 May 2008 23:43:56 +0200 Subject: removed some unused stuff --- lib/git_python/git.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/git_python/git.py b/lib/git_python/git.py index 25cd1cce..8711c1fb 100644 --- a/lib/git_python/git.py +++ b/lib/git_python/git.py @@ -74,10 +74,10 @@ class Git(MethodMissingMixin): str """ opt_args = self.transform_kwargs(**kwargs) - ext_args = map(lambda a: (a == '--') and a or "%s" % a, args) - args = opt_args + ext_args + args = opt_args + list(args) call = ['git-'+dashify(method)] call.extend(args) + stdout_value = self.execute(call) return stdout_value -- cgit v1.2.3 From 71cd409660bc5b8c211dc7c51afae481d822d593 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Wed, 21 May 2008 19:39:55 +0200 Subject: fixed errors in the test, two permission errors remaining, thx to mock?!?! Also removed the shell_escape tests... --- lib/git_python/git.py | 4 +++- test/git/test_git.py | 26 +++----------------------- test/git/test_utils.py | 6 +++--- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/lib/git_python/git.py b/lib/git_python/git.py index 8711c1fb..2cec4954 100644 --- a/lib/git_python/git.py +++ b/lib/git_python/git.py @@ -25,6 +25,7 @@ class Git(MethodMissingMixin): The command to execute """ print ' '.join(command) + print self.git_dir proc = subprocess.Popen(command, cwd = self.git_dir, stdout=subprocess.PIPE @@ -74,7 +75,8 @@ class Git(MethodMissingMixin): str """ opt_args = self.transform_kwargs(**kwargs) - args = opt_args + list(args) + ext_args = map(lambda a: (a == '--') and a or "%s" % a, args) + args = opt_args + ext_args call = ['git-'+dashify(method)] call.extend(args) diff --git a/test/git/test_git.py b/test/git/test_git.py index 0634a5dd..43fd231c 100644 --- a/test/git/test_git.py +++ b/test/git/test_git.py @@ -4,9 +4,8 @@ from git_python import * class TestGit(object): def setup(self): - base = os.path.join(os.path.dirname(__file__), "../.."), + base = os.path.join(os.path.dirname(__file__), "../..") self.git = Git(base) - self.git_bin_base = "%s --git-dir=%s" % (Git.git_binary, base) @patch(Git, 'execute') def test_method_missing_calls_execute(self, git): @@ -17,7 +16,7 @@ class TestGit(object): def test_it_transforms_kwargs_into_git_command_arguments(self): assert_equal(["-s"], self.git.transform_kwargs(**{'s': True})) - assert_equal(["-s 5"], self.git.transform_kwargs(**{'s': 5})) + assert_equal(["-s", 5], self.git.transform_kwargs(**{'s': 5})) assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True})) assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5})) @@ -25,23 +24,4 @@ class TestGit(object): assert_equal(["-s", "-t"], self.git.transform_kwargs(**{'s': True, 't': True})) def test_it_executes_git_to_shell_and_returns_result(self): - assert_match('^git version [\d\.]*$', self.git.execute("%s version" % Git.git_binary)) - - def test_it_transforms_kwargs_shell_escapes_arguments(self): - assert_equal(["--foo=\"bazz'er\""], self.git.transform_kwargs(**{'foo': "bazz'er"})) - assert_equal(["-x \"bazz'er\""], self.git.transform_kwargs(**{'x': "bazz'er"})) - - @patch(Git, 'execute') - def test_it_really_shell_escapes_arguments_to_the_git_shell_1(self, git): - self.git.foo(**{'bar': "bazz'er"}) - assert_true(git.called) - assert_equal(git.call_args, ((("%s foo --bar=\"bazz'er\"" % self.git_bin_base),), {})) - - @patch(Git, 'execute') - def test_it_really_shell_escapes_arguments_to_the_git_shell_2(self, git): - self.git.bar(**{'x': "quu'x"}) - assert_true(git.called) - assert_equal(git.call_args, ((("%s bar -x \"quu'x\"" % self.git_bin_base),), {})) - - def test_it_shell_escapes_the_standalone_argument(self): - self.git.foo("bar's", {}) + assert_match('^git version [\d\.]*$', self.git.execute(["git","version"])) diff --git a/test/git/test_utils.py b/test/git/test_utils.py index a9af2040..b2b42a1c 100644 --- a/test/git/test_utils.py +++ b/test/git/test_utils.py @@ -6,10 +6,10 @@ class TestUtils(object): def setup(self): base = os.path.join(os.path.dirname(__file__), "../.."), self.git = Git(base) - self.git_bin_base = "%s --git-dir='%s'" % (Git.git_binary, base) +# self.git_bin_base = "%s --git-dir='%s'" % (Git.git_binary, base) - def test_it_escapes_single_quotes_with_shell_escape(self): - assert_equal("\\\\'foo", shell_escape("'foo")) +# def test_it_escapes_single_quotes_with_shell_escape(self): +# assert_equal("\\\\'foo", shell_escape("'foo")) def test_it_should_dashify(self): assert_equal('this-is-my-argument', dashify('this_is_my_argument')) -- cgit v1.2.3 From 5962862e9ba0a1c9a14306688973946f6f7ce75c Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Thu, 22 May 2008 22:11:22 +0200 Subject: use ~/foo instead of /foo for repo. --- test/git/test_repo.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 52f5856d..ff267956 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -13,7 +13,7 @@ class TestRepo(object): @raises(NoSuchPathError) def test_new_should_raise_on_non_existant_path(self): - Repo("/foobar") + Repo("~/foobar") def test_description(self): assert_equal("Unnamed repository; edit this file to name it for gitweb.", self.repo.description) @@ -108,34 +108,34 @@ class TestRepo(object): def test_init_bare(self, repo, git): git.return_value = True - Repo.init_bare("/foo/bar.git") + Repo.init_bare("~/foo/bar.git") assert_true(git.called) assert_equal(git.call_args, (('init',), {})) assert_true(repo.called) - assert_equal(repo.call_args, (('/foo/bar.git',), {})) + assert_equal(repo.call_args, (('~/foo/bar.git',), {})) @patch(Repo, '__init__') @patch(Git, 'method_missing') def test_init_bare_with_options(self, repo, git): git.return_value = True - Repo.init_bare("/foo/bar.git", **{'template': "/baz/sweet"}) + Repo.init_bare("~/foo/bar.git", **{'template': "/baz/sweet"}) assert_true(git.called) assert_equal(git.call_args, (('init',), {'template': '/baz/sweet'})) assert_true(repo.called) - assert_equal(repo.call_args, (('/foo/bar.git',), {})) + assert_equal(repo.call_args, (('~/foo/bar.git',), {})) @patch(Repo, '__init__') @patch(Git, 'method_missing') def test_fork_bare(self, repo, git): git.return_value = None - self.repo.fork_bare("/foo/bar.git") + self.repo.fork_bare("~/foo/bar.git") assert_true(git.called) - assert_equal(git.call_args, (('clone', '%s/.git' % absolute_project_path(), '/foo/bar.git'), {'bare': True})) + assert_equal(git.call_args, (('clone', '%s/.git' % absolute_project_path(), '~/foo/bar.git'), {'bare': True})) assert_true(repo.called) @patch(Repo, '__init__') @@ -143,10 +143,10 @@ class TestRepo(object): def test_fork_bare_with_options(self, repo, git): git.return_value = None - self.repo.fork_bare("/foo/bar.git", **{'template': '/awesome'}) + self.repo.fork_bare("~/foo/bar.git", **{'template': '/awesome'}) assert_true(git.called) - assert_equal(git.call_args, (('clone', '%s/.git' % absolute_project_path(), '/foo/bar.git'), + assert_equal(git.call_args, (('clone', '%s/.git' % absolute_project_path(), '~/foo/bar.git'), {'bare': True, 'template': '/awesome'})) assert_true(repo.called) -- cgit v1.2.3 From 70094734d601e1220c95ac586fdffbda3a23e10b Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Thu, 22 May 2008 23:12:48 +0200 Subject: removed stupid print --- lib/git_python/git.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/git_python/git.py b/lib/git_python/git.py index 2cec4954..aad1f85d 100644 --- a/lib/git_python/git.py +++ b/lib/git_python/git.py @@ -25,7 +25,6 @@ class Git(MethodMissingMixin): The command to execute """ print ' '.join(command) - print self.git_dir proc = subprocess.Popen(command, cwd = self.git_dir, stdout=subprocess.PIPE -- cgit v1.2.3