mirror of
https://github.com/powerline/powerline.git
synced 2025-07-23 13:55:45 +02:00
Merge pull request #905 from ZyX-I/fix-876
Fix support for .git git symlinks
This commit is contained in:
commit
7879142aeb
@ -33,6 +33,8 @@ def git_directory(directory):
|
|||||||
if not raw.startswith(b'gitdir: '):
|
if not raw.startswith(b'gitdir: '):
|
||||||
raise IOError('invalid gitfile format')
|
raise IOError('invalid gitfile format')
|
||||||
raw = raw[8:].decode(sys.getfilesystemencoding() or 'utf-8')
|
raw = raw[8:].decode(sys.getfilesystemencoding() or 'utf-8')
|
||||||
|
if raw[-1] == '\n':
|
||||||
|
raw = raw[:-1]
|
||||||
if not raw:
|
if not raw:
|
||||||
raise IOError('no path in gitfile')
|
raise IOError('no path in gitfile')
|
||||||
return os.path.abspath(os.path.join(directory, raw))
|
return os.path.abspath(os.path.join(directory, raw))
|
||||||
@ -78,9 +80,10 @@ class GitRepository(object):
|
|||||||
return self.do_status(self.directory, path)
|
return self.do_status(self.directory, path)
|
||||||
|
|
||||||
def branch(self):
|
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(
|
return get_branch_name(
|
||||||
directory=self.directory,
|
directory=directory,
|
||||||
config_file=head,
|
config_file=head,
|
||||||
get_func=branch_name_from_config_file,
|
get_func=branch_name_from_config_file,
|
||||||
create_watcher=self.create_watcher,
|
create_watcher=self.create_watcher,
|
||||||
|
@ -7,6 +7,7 @@ from powerline.lib.vcs import guess, get_fallback_create_watcher
|
|||||||
from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment
|
from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment
|
||||||
from powerline.lib.monotonic import monotonic
|
from powerline.lib.monotonic import monotonic
|
||||||
from powerline.lib.file_watcher import create_file_watcher, INotifyError
|
from powerline.lib.file_watcher import create_file_watcher, INotifyError
|
||||||
|
from powerline.lib.vcs.git import git_directory
|
||||||
from powerline import get_fallback_logger
|
from powerline import get_fallback_logger
|
||||||
import threading
|
import threading
|
||||||
import os
|
import os
|
||||||
@ -508,18 +509,34 @@ class TestVCS(TestCase):
|
|||||||
os.remove(os.path.join(GIT_REPO, 'file'))
|
os.remove(os.path.join(GIT_REPO, 'file'))
|
||||||
# Test changing branch
|
# Test changing branch
|
||||||
self.assertEqual(repo.branch(), 'master')
|
self.assertEqual(repo.branch(), 'master')
|
||||||
|
try:
|
||||||
call(['git', 'branch', 'branch1'], cwd=GIT_REPO)
|
call(['git', 'branch', 'branch1'], cwd=GIT_REPO)
|
||||||
call(['git', 'checkout', '-q', 'branch1'], cwd=GIT_REPO)
|
call(['git', 'checkout', '-q', 'branch1'], cwd=GIT_REPO)
|
||||||
self.do_branch_rename_test(repo, 'branch1')
|
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', 'branch', 'branch2'], cwd=GIT_REPO)
|
||||||
call(['git', 'checkout', '-q', 'branch2'], cwd=GIT_REPO)
|
call(['git', 'checkout', '-q', 'branch2'], cwd=GIT_REPO)
|
||||||
self.do_branch_rename_test(repo, 'branch2')
|
self.do_branch_rename_test(repo, 'branch2')
|
||||||
call(['git', 'checkout', '-q', '--detach', 'branch1'], cwd=GIT_REPO)
|
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)
|
||||||
|
|
||||||
|
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:
|
if use_mercurial:
|
||||||
def test_mercurial(self):
|
def test_mercurial(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user