From abb4ed4efccb0f53cab28ddd6e1628707bf02fa7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 28 Jun 2014 21:28:45 +0400 Subject: [PATCH 1/6] Support .git files with newline at the end Fixes #876 --- powerline/lib/vcs/git.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/powerline/lib/vcs/git.py b/powerline/lib/vcs/git.py index 3bf60562..a8b36aea 100644 --- a/powerline/lib/vcs/git.py +++ b/powerline/lib/vcs/git.py @@ -33,6 +33,8 @@ def git_directory(directory): if not raw.startswith(b'gitdir: '): raise IOError('invalid gitfile format') raw = raw[8:].decode(sys.getfilesystemencoding() or 'utf-8') + if raw[-1] == '\n': + raw = raw[:-1] if not raw: raise IOError('no path in gitfile') return os.path.abspath(os.path.join(directory, raw)) From 803963af1550d2604d49266c9ec7e1beef235c58 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 28 Jun 2014 21:45:08 +0400 Subject: [PATCH 2/6] Fix git symlink handling --- powerline/lib/vcs/git.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/powerline/lib/vcs/git.py b/powerline/lib/vcs/git.py index a8b36aea..27a1e71a 100644 --- a/powerline/lib/vcs/git.py +++ b/powerline/lib/vcs/git.py @@ -80,9 +80,10 @@ class GitRepository(object): return self.do_status(self.directory, path) def branch(self): - head = os.path.join(git_directory(self.directory), 'HEAD') + directory = git_directory(self.directory) + head = os.path.join(directory, 'HEAD') return get_branch_name( - directory=self.directory, + directory=directory, config_file=head, get_func=branch_name_from_config_file, create_watcher=self.create_watcher, From 317f4be43f06f29601a6fc2a01054d386bb4e798 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 28 Jun 2014 21:45:24 +0400 Subject: [PATCH 3/6] Add tests for git symlinks --- tests/test_lib.py | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/tests/test_lib.py b/tests/test_lib.py index 0bbae4e4..153ab9fa 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -7,6 +7,7 @@ from powerline.lib.vcs import guess, get_fallback_create_watcher from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment from powerline.lib.monotonic import monotonic from powerline.lib.file_watcher import create_file_watcher, INotifyError +from powerline.lib.vcs.git import git_directory from powerline import get_fallback_logger import threading import os @@ -508,18 +509,38 @@ class TestVCS(TestCase): os.remove(os.path.join(GIT_REPO, 'file')) # Test changing branch self.assertEqual(repo.branch(), 'master') - call(['git', 'branch', 'branch1'], cwd=GIT_REPO) - call(['git', 'checkout', '-q', 'branch1'], cwd=GIT_REPO) - self.do_branch_rename_test(repo, 'branch1') - # For some reason the rest of this test fails on travis and only on - # travis, and I can't figure out why - if 'TRAVIS' in os.environ: - raise SkipTest('Part of this test fails on Travis for unknown reasons') - call(['git', 'branch', 'branch2'], cwd=GIT_REPO) - call(['git', 'checkout', '-q', 'branch2'], cwd=GIT_REPO) - self.do_branch_rename_test(repo, 'branch2') - call(['git', 'checkout', '-q', '--detach', 'branch1'], cwd=GIT_REPO) - self.do_branch_rename_test(repo, lambda b: re.match(r'^[a-f0-9]+$', b)) + try: + call(['git', 'branch', 'branch1'], cwd=GIT_REPO) + call(['git', 'checkout', '-q', 'branch1'], cwd=GIT_REPO) + self.do_branch_rename_test(repo, 'branch1') + # For some reason the rest of this test fails on travis and only on + # travis, and I can't figure out why + if 'TRAVIS' in os.environ: + raise SkipTest('Part of this test fails on Travis for unknown reasons') + call(['git', 'branch', 'branch2'], cwd=GIT_REPO) + call(['git', 'checkout', '-q', 'branch2'], cwd=GIT_REPO) + self.do_branch_rename_test(repo, 'branch2') + call(['git', 'checkout', '-q', '--detach', 'branch1'], cwd=GIT_REPO) + self.do_branch_rename_test(repo, lambda b: re.match(r'^[a-f0-9]+$', b)) + finally: + call(['git', 'checkout', '-q', 'master'], cwd=GIT_REPO) + + def test_git_sym(self): + create_watcher = get_fallback_create_watcher() + dotgit = os.path.join(GIT_REPO, '.git') + spacegit = os.path.join(GIT_REPO, ' .git ') + os.rename(dotgit, spacegit) + try: + with open(dotgit, 'w') as F: + F.write('gitdir: .git \n') + gitdir = git_directory(GIT_REPO) + self.assertTrue(os.path.isdir(gitdir)) + self.assertEqual(gitdir, os.path.abspath(spacegit)) + repo = guess(path=GIT_REPO, create_watcher=create_watcher) + self.assertEqual(repo.branch(), 'master') + finally: + os.remove(dotgit) + os.rename(spacegit, dotgit) if use_mercurial: def test_mercurial(self): From 4d4da5683811eb7a24e866eb78a05d19659a80e4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 28 Jun 2014 21:46:12 +0400 Subject: [PATCH 4/6] Check whether it runs fine in travis --- tests/test_lib.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_lib.py b/tests/test_lib.py index 153ab9fa..4e108e09 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -515,8 +515,6 @@ class TestVCS(TestCase): self.do_branch_rename_test(repo, 'branch1') # For some reason the rest of this test fails on travis and only on # travis, and I can't figure out why - if 'TRAVIS' in os.environ: - raise SkipTest('Part of this test fails on Travis for unknown reasons') call(['git', 'branch', 'branch2'], cwd=GIT_REPO) call(['git', 'checkout', '-q', 'branch2'], cwd=GIT_REPO) self.do_branch_rename_test(repo, 'branch2') From d7d8108230e18c1984d9443152ad4abd04f53d4f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 28 Jun 2014 21:54:21 +0400 Subject: [PATCH 5/6] Fix error in python-3* that happens while checking branch name --- tests/test_lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_lib.py b/tests/test_lib.py index 4e108e09..b554f004 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -519,7 +519,7 @@ class TestVCS(TestCase): call(['git', 'checkout', '-q', 'branch2'], cwd=GIT_REPO) self.do_branch_rename_test(repo, 'branch2') call(['git', 'checkout', '-q', '--detach', 'branch1'], cwd=GIT_REPO) - self.do_branch_rename_test(repo, lambda b: re.match(r'^[a-f0-9]+$', b)) + self.do_branch_rename_test(repo, lambda b: re.match(br'^[a-f0-9]+$', b)) finally: call(['git', 'checkout', '-q', 'master'], cwd=GIT_REPO) From 623395a0130299c5bfcecd5505be3855c8a764ee Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 28 Jun 2014 22:18:45 +0400 Subject: [PATCH 6/6] Remove outdated comment --- tests/test_lib.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_lib.py b/tests/test_lib.py index b554f004..c69d97b6 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -513,8 +513,6 @@ class TestVCS(TestCase): call(['git', 'branch', 'branch1'], cwd=GIT_REPO) call(['git', 'checkout', '-q', 'branch1'], cwd=GIT_REPO) self.do_branch_rename_test(repo, 'branch1') - # For some reason the rest of this test fails on travis and only on - # travis, and I can't figure out why call(['git', 'branch', 'branch2'], cwd=GIT_REPO) call(['git', 'checkout', '-q', 'branch2'], cwd=GIT_REPO) self.do_branch_rename_test(repo, 'branch2')