Example #1
0
 def test_git(self):
     repo = guess(path=GIT_REPO)
     self.assertNotEqual(repo, None)
     self.assertEqual(repo.branch(), 'master')
     self.assertEqual(repo.status(), None)
     self.assertEqual(repo.status('file'), None)
     with open(os.path.join(GIT_REPO, 'file'), 'w') as f:
         f.write('abc')
         f.flush()
         self.assertEqual(repo.status(), '  U')
         self.assertEqual(repo.status('file'), '??')
         call(['git', 'add', '.'], cwd=GIT_REPO)
         self.assertEqual(repo.status(), ' I ')
         self.assertEqual(repo.status('file'), 'A ')
         f.write('def')
         f.flush()
         self.assertEqual(repo.status(), 'DI ')
         self.assertEqual(repo.status('file'), 'AM')
     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))
Example #2
0
def branch(pl, segment_info, status_colors=False):
    '''Return the current working branch.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.

	Divider highlight group used: ``branch:divider``.
	'''
    name = segment_info['buffer'].name
    skip = not (name and (not vim_getbufoption(segment_info, 'buftype')))
    if not skip:
        repo = guess(path=name)
        if repo is not None:
            branch = repo.branch()
            scol = ['branch']
            if status_colors:
                status = tree_status(repo, pl)
                scol.insert(
                    0, 'branch_dirty'
                    if status and status.strip() else 'branch_clean')
            return [{
                'contents': branch,
                'highlight_group': scol,
                'divider_highlight_group': 'branch:divider',
            }]
Example #3
0
 def test_git(self):
     create_watcher = get_fallback_create_watcher()
     repo = guess(path=GIT_REPO, create_watcher=create_watcher)
     self.assertNotEqual(repo, None)
     self.assertEqual(repo.branch(), 'master')
     self.assertEqual(repo.status(), None)
     self.assertEqual(repo.status('file'), None)
     with open(os.path.join(GIT_REPO, 'file'), 'w') as f:
         f.write('abc')
         f.flush()
         self.assertEqual(repo.status(), '  U')
         self.assertEqual(repo.status('file'), '??')
         call(['git', 'add', '.'], cwd=GIT_REPO)
         self.assertEqual(repo.status(), ' I ')
         self.assertEqual(repo.status('file'), 'A ')
         f.write('def')
         f.flush()
         self.assertEqual(repo.status(), 'DI ')
         self.assertEqual(repo.status('file'), 'AM')
     os.remove(os.path.join(GIT_REPO, 'file'))
     # Test changing branch
     self.assertEqual(repo.branch(), 'master')
     try:
         call(['git', 'branch', 'branch1'], cwd=GIT_REPO)
         call(['git', 'checkout', '-q', 'branch1'], cwd=GIT_REPO)
         self.do_branch_rename_test(repo, 'branch1')
         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)
Example #4
0
def vcs_status():
  from powerline.lib.vcs import guess
  repo = guess(os.path.abspath(os.getcwd()))
  if repo and repo.status():
    return "X"
  else:
    return None
Example #5
0
 def __call__(self,
              pl,
              segment_info,
              create_watcher,
              status_colors=False,
              ignore_statuses=()):
     name = self.get_directory(segment_info)
     if name:
         repo = guess(path=name, create_watcher=create_watcher)
         if repo is not None:
             branch = repo.branch()
             scol = ['branch']
             if status_colors:
                 try:
                     status = tree_status(repo, pl)
                 except Exception as e:
                     pl.exception('Failed to compute tree status: {0}',
                                  str(e))
                     status = '?'
                 else:
                     status = status and status.strip()
                     if status in ignore_statuses:
                         status = None
                 scol.insert(0,
                             'branch_dirty' if status else 'branch_clean')
             return [{
                 'contents':
                 branch,
                 'highlight_groups':
                 scol,
                 'divider_highlight_group':
                 self.divider_highlight_group,
             }]
Example #6
0
	def test_git(self):
		create_watcher = get_fallback_create_watcher()
		repo = guess(path=GIT_REPO, create_watcher=create_watcher)
		self.assertNotEqual(repo, None)
		self.assertEqual(repo.branch(), 'master')
		self.assertEqual(repo.status(), None)
		self.assertEqual(repo.status('file'), None)
		with open(os.path.join(GIT_REPO, 'file'), 'w') as f:
			f.write('abc')
			f.flush()
			self.assertEqual(repo.status(), '  U')
			self.assertEqual(repo.status('file'), '??')
			call(['git', 'add', '.'], cwd=GIT_REPO)
			self.assertEqual(repo.status(), ' I ')
			self.assertEqual(repo.status('file'), 'A ')
			f.write('def')
			f.flush()
			self.assertEqual(repo.status(), 'DI ')
			self.assertEqual(repo.status('file'), 'AM')
		os.remove(os.path.join(GIT_REPO, 'file'))
		# Test changing branch
		self.assertEqual(repo.branch(), 'master')
		try:
			call(['git', 'branch', 'branch1'], cwd=GIT_REPO)
			call(['git', 'checkout', '-q', 'branch1'], cwd=GIT_REPO)
			self.do_branch_rename_test(repo, 'branch1')
			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)
Example #7
0
 def test_git(self):
     repo = guess(path=GIT_REPO)
     self.assertNotEqual(repo, None)
     self.assertEqual(repo.branch(), "master")
     self.assertEqual(repo.status(), None)
     self.assertEqual(repo.status("file"), None)
     with open(os.path.join(GIT_REPO, "file"), "w") as f:
         f.write("abc")
         f.flush()
         self.assertEqual(repo.status(), "  U")
         self.assertEqual(repo.status("file"), "??")
         call(["git", "add", "."], cwd=GIT_REPO)
         self.assertEqual(repo.status(), " I ")
         self.assertEqual(repo.status("file"), "A ")
         f.write("def")
         f.flush()
         self.assertEqual(repo.status(), "DI ")
         self.assertEqual(repo.status("file"), "AM")
     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, "[DETACHED HEAD]")
Example #8
0
def branch(pl, segment_info, status_colors=False, path=None):
    '''Return the current VCS branch in specified directory.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.
	:param string path:
		determines which directory will be watched.
		current directory will be set if this is None. Default: None.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
	'''
    if path is None: path = segment_info['getcwd']()
    repo = guess(path=path)
    if repo is not None:
        branch = repo.branch()
        scol = ['branch']
        if status_colors:
            status = tree_status(repo, pl)
            scol.insert(
                0, 'branch_dirty'
                if status and status.strip() else 'branch_clean')
        return [{
            'contents': branch,
            'highlight_group': scol,
        }]
Example #9
0
def branch(pl, segment_info, create_watcher, status_colors=False):
    '''Return the current VCS branch.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
	'''
    name = segment_info['getcwd']()
    repo = guess(path=name, create_watcher=create_watcher)
    if repo is not None:
        branch = repo.branch()
        scol = ['branch']
        if status_colors:
            try:
                status = tree_status(repo, pl)
            except Exception as e:
                pl.exception('Failed to compute tree status: {0}', str(e))
                status = '?'
            scol.insert(
                0, 'branch_dirty'
                if status and status.strip() else 'branch_clean')
        return [{
            'contents': branch,
            'highlight_group': scol,
        }]
Example #10
0
	def __call__(self, pl, segment_info, create_watcher, status_colors=False, ignore_statuses=()):
		name = self.get_directory(segment_info)
		if name:
			repo = guess(path=name, create_watcher=create_watcher)
			if repo is not None:
				branch = repo.branch()
				scol = ['branch']
				if status_colors:
					try:
						status = tree_status(repo, pl)
					except Exception as e:
						pl.exception('Failed to compute tree status: {0}', str(e))
						status = '?'
					else:
						status = status and status.strip()
						if status:
							if 'U' in status:
								branch += ' +'
							if 'D' in status:
								status = 'branch_dirty'
							else:
								status = 'branch_clean'
						else:
							status = 'branch_clean'
						if status in ignore_statuses:
							status = None
					scol.insert(0, status)
				return [{
					'contents': branch,
					'highlight_groups': scol,
					'divider_highlight_group': self.divider_highlight_group,
				}]
Example #11
0
def branch():
	'''Return the current VCS branch.'''
	from powerline.lib.vcs import guess
	repo = guess(path=os.path.abspath(os.getcwd()))
	if repo:
		return repo.branch()
	return None
Example #12
0
def branch(pl, segment_info, status_colors=False):
	'''Return the current VCS branch.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
	'''
	name = segment_info['getcwd']()
        return name
	repo = guess(path=name)
        return [{
            'contents': repo,
            'highlight_group': ['branch_clean', 'branch']
        }]
	if repo is not None:
		branch = repo.branch()
		scol = ['branch']
		if status_colors:
			status = tree_status(repo, pl)
			scol.insert(0, 'branch_dirty' if status and status.strip() else 'branch_clean')
		return [{
			'contents': branch,
			'highlight_group': scol,
		}]
Example #13
0
	def test_git(self):
		repo = guess(path=GIT_REPO)
		self.assertNotEqual(repo, None)
		self.assertEqual(repo.branch(), 'master')
		self.assertEqual(repo.status(), None)
		self.assertEqual(repo.status('file'), None)
		with open(os.path.join(GIT_REPO, 'file'), 'w') as f:
			f.write('abc')
			f.flush()
			self.assertEqual(repo.status(), '  U')
			self.assertEqual(repo.status('file'), '??')
			call(['git', 'add', '.'], cwd=GIT_REPO)
			self.assertEqual(repo.status(), ' I ')
			self.assertEqual(repo.status('file'), 'A ')
			f.write('def')
			f.flush()
			self.assertEqual(repo.status(), 'DI ')
			self.assertEqual(repo.status('file'), 'AM')
		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))
Example #14
0
def branch(pl, segment_info, status_colors=False):
	'''Return the current working branch.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.

	Divider highlight group used: ``branch:divider``.
	'''
	name = segment_info['buffer'].name
	skip = not (name and (not vim_getbufoption(segment_info, 'buftype')))
	if not skip:
		repo = guess(path=name)
		if repo is not None:
			branch = repo.branch()
			scol = ['branch']
			if status_colors:
				status = tree_status(repo, pl)
				scol.insert(0, 'branch_dirty' if status and status.strip() else 'branch_clean')
			return [{
				'contents': branch,
				'highlight_group': scol,
				'divider_highlight_group': 'branch:divider',
			}]
Example #15
0
 def __call__(self, pl, segment_info, create_watcher, **kwargs):
     directory = self.get_directory(segment_info)
     if directory:
         repo = guess(path=directory, create_watcher=create_watcher)
         if repo is not None:
             return self.get_property(pl, repo, **kwargs)
     return None
Example #16
0
	def compute_state(self, path):
		repo = guess(path=path)
		if repo:
			if repo.directory in self.directories:
				return self.directories[repo.directory]
			else:
				r = self.process_repo(repo)
				self.directories[repo.directory] = r
				return r
Example #17
0
def branch(segment_info):
	'''Return the current working branch.'''
	repo = guess(path=os.path.abspath(segment_info['buffer'].name or os.getcwd()))
	if repo:
		return [{
			'contents': repo.branch(),
			'divider_highlight_group': 'branch:divider',
		}]
	return None
Example #18
0
def branch():
    from powerline.lib.vcs import guess
    repo = guess(os.path.abspath(os.getcwd()))
    if repo:
        branch = repo.branch()
        return [{
            'contents': branch,
            'highlight_group': 'branch' if branch != 'master' else ['masterbranch', 'branch'],
        }]
    return None
Example #19
0
def branch():
    from powerline.lib.vcs import guess
    repo = guess(os.path.abspath(os.getcwd()))
    if repo:
        branch = repo.branch()
        return [{
            'contents':
            branch,
            'highlight_group':
            'branch' if branch != 'master' else ['masterbranch', 'branch'],
        }]
    return None
Example #20
0
		def test_mercurial(self):
			repo = guess(path='hg_repo')
			self.assertNotEqual(repo, None)
			self.assertEqual(repo.branch(), 'default')
			with open(os.path.join('hg_repo', 'file'), 'w') as f:
				f.write('abc')
				f.flush()
				self.assertEqual(repo.status(), ' U')
				self.assertEqual(repo.status('file'), 'U')
				call(['hg', 'add', '.'], cwd='hg_repo', stdout=PIPE)
				self.assertEqual(repo.status(), 'D ')
				self.assertEqual(repo.status('file'), 'A')
			os.remove(os.path.join('hg_repo', 'file'))
Example #21
0
 def test_mercurial(self):
     repo = guess(path=HG_REPO)
     self.assertNotEqual(repo, None)
     self.assertEqual(repo.branch(), "default")
     self.assertEqual(repo.status(), None)
     with open(os.path.join(HG_REPO, "file"), "w") as f:
         f.write("abc")
         f.flush()
         self.assertEqual(repo.status(), " U")
         self.assertEqual(repo.status("file"), "U")
         call(["hg", "add", "."], cwd=HG_REPO, stdout=PIPE)
         self.assertEqual(repo.status(), "D ")
         self.assertEqual(repo.status("file"), "A")
     os.remove(os.path.join(HG_REPO, "file"))
Example #22
0
 def test_mercurial(self):
     repo = guess(path=HG_REPO)
     self.assertNotEqual(repo, None)
     self.assertEqual(repo.branch(), 'default')
     self.assertEqual(repo.status(), None)
     with open(os.path.join(HG_REPO, 'file'), 'w') as f:
         f.write('abc')
         f.flush()
         self.assertEqual(repo.status(), ' U')
         self.assertEqual(repo.status('file'), 'U')
         call(['hg', 'add', '.'], cwd=HG_REPO, stdout=PIPE)
         self.assertEqual(repo.status(), 'D ')
         self.assertEqual(repo.status('file'), 'A')
     os.remove(os.path.join(HG_REPO, 'file'))
Example #23
0
	def __call__(self, pl, segment_info, create_watcher):
		name = self.get_directory(segment_info)
		if name:
			repo = guess(path=name, create_watcher=create_watcher)
			if repo is not None:
				stash = getattr(repo, 'stash', None)
				if stash:
					stashes = stash()
					if stashes:
						return [{
							'contents': str(stashes),
							'highlight_groups': ['stash'],
							'divider_highlight_group': self.divider_highlight_group
						}]
Example #24
0
		def test_mercurial(self):
			create_watcher = get_fallback_create_watcher()
			repo = guess(path=HG_REPO, create_watcher=create_watcher)
			self.assertNotEqual(repo, None)
			self.assertEqual(repo.branch(), 'default')
			self.assertEqual(repo.status(), None)
			with open(os.path.join(HG_REPO, 'file'), 'w') as f:
				f.write('abc')
				f.flush()
				self.assertEqual(repo.status(), ' U')
				self.assertEqual(repo.status('file'), 'U')
				call(['hg', 'add', '.'], cwd=HG_REPO, stdout=PIPE)
				self.assertEqual(repo.status(), 'D ')
				self.assertEqual(repo.status('file'), 'A')
			os.remove(os.path.join(HG_REPO, 'file'))
Example #25
0
 def compute_state(key):
     name, skip = key
     if not skip:
         repo = guess(path=name)
         if repo:
             status = repo.status(os.path.relpath(name, repo.directory))
             if not status:
                 return None
             status = status.strip()
             ret = []
             for status in status:
                 ret.append(
                     {"contents": status, "highlight_group": ["file_vcs_status_" + status, "file_vcs_status"]}
                 )
             return ret
     return None
Example #26
0
	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)
Example #27
0
 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)
Example #28
0
 def __call__(self, pl, segment_info, create_watcher):
     name = self.get_directory(segment_info)
     if name:
         repo = guess(path=name, create_watcher=create_watcher)
         if repo is not None:
             stash = getattr(repo, 'stash', None)
             if stash:
                 stashes = stash()
                 if stashes:
                     return [{
                         'contents':
                         str(stashes),
                         'highlight_groups': ['stash'],
                         'divider_highlight_group':
                         self.divider_highlight_group
                     }]
Example #29
0
 def test_mercurial(self):
     if not use_mercurial:
         raise SkipTest('Mercurial is not available')
     create_watcher = get_fallback_create_watcher()
     repo = guess(path=HG_REPO, create_watcher=create_watcher)
     self.assertNotEqual(repo, None)
     self.assertEqual(repo.branch(), 'default')
     self.assertEqual(repo.status(), None)
     with open(os.path.join(HG_REPO, 'file'), 'w') as f:
         f.write('abc')
         f.flush()
         self.assertEqual(repo.status(), ' U')
         self.assertEqual(repo.status('file'), 'U')
         call(['hg', 'add', '.'], cwd=HG_REPO, stdout=PIPE)
         self.assertEqual(repo.status(), 'D ')
         self.assertEqual(repo.status('file'), 'A')
     os.remove(os.path.join(HG_REPO, 'file'))
Example #30
0
def branch(pl, segment_info, status_colors=False):
    """Return the current VCS branch.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
	"""
    name = segment_info["getcwd"]()
    repo = guess(path=name)
    if repo is not None:
        branch = repo.branch()
        scol = ["branch"]
        if status_colors:
            status = tree_status(repo, pl)
            scol.insert(0, "branch_dirty" if status and status.strip() else "branch_clean")
        return [{"contents": branch, "highlight_group": scol}]
Example #31
0
	def compute_state(key):
		name, skip = key
		if not skip:
			repo = guess(path=name)
			if repo:
				status = repo.status(os.path.relpath(name, repo.directory))
				if not status:
					return None
				status = status.strip()
				ret = []
				for status in status:
					ret.append({
						'contents': status,
						'highlight_group': ['file_vcs_status_' + status, 'file_vcs_status'],
					})
				return ret
		return None
Example #32
0
def branch(segment_info, status_colors=True):
	'''Return the current working branch.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: True.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.

	Divider highlight group used: ``branch:divider``.
	'''
	repo = guess(path=os.path.abspath(segment_info['buffer'].name or os.getcwd()))
	if repo:
		return [{
			'contents': repo.branch(),
			'highlight_group': (['branch_dirty' if repo.status() else 'branch_clean'] if status_colors else []) + ['branch'],
			'divider_highlight_group': 'branch:divider',
		}]
	return None
Example #33
0
def file_vcs_status(segment_info):
	'''Return the VCS status for this buffer.'''
	name = segment_info['buffer'].name
	if name and not getbufvar(segment_info['bufnr'], '&buftype'):
		repo = guess(path=os.path.abspath(name))
		if repo:
			status = repo.status(os.path.relpath(name, repo.directory))
			if not status:
				return None
			status = status.strip()
			ret = []
			for status in status:
				ret.append({
					'contents': status,
					'highlight_group': ['file_vcs_status_' + status, 'file_vcs_status'],
					})
			return ret
	return None
Example #34
0
def file_vcs_status(pl, segment_info, create_watcher):
    """Return the VCS status for this buffer.

	Highlight groups used: ``file_vcs_status``.
	"""
    name = segment_info["buffer"].name
    skip = not (name and (not vim_getbufoption(segment_info, "buftype")))
    if not skip:
        repo = guess(path=name, create_watcher=create_watcher)
        if repo is not None:
            status = repo.status(os.path.relpath(name, repo.directory))
            if not status:
                return None
            status = status.strip()
            ret = []
            for status in status:
                ret.append({"contents": status, "highlight_group": ["file_vcs_status_" + status, "file_vcs_status"]})
            return ret
Example #35
0
def branch(status_colors=True):
	'''Return the current VCS branch.@

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: True.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
	'''
	repo = guess(path=os.path.abspath(os.getcwd()))
	if repo:
		branch = repo.branch()
		if status_colors:
			return [{
				'contents': branch,
				'highlight_group': ['branch_dirty' if repo.status() else 'branch_clean', 'branch'],
				}]
		else:
			return branch
	return None
Example #36
0
	def test_git(self):
		repo = guess(path='git_repo')
		self.assertNotEqual(repo, None)
		self.assertEqual(repo.branch(), 'master')
		self.assertEqual(repo.status(), '   ')
		self.assertEqual(repo.status('file'), None)
		with open(os.path.join('git_repo', 'file'), 'w') as f:
			f.write('abc')
			f.flush()
			self.assertEqual(repo.status(), '  U')
			self.assertEqual(repo.status('file'), '??')
			call(['git', 'add', '.'], cwd='git_repo')
			self.assertEqual(repo.status(), ' I ')
			self.assertEqual(repo.status('file'), 'A ')
			f.write('def')
			f.flush()
			self.assertEqual(repo.status(), 'DI ')
			self.assertEqual(repo.status('file'), 'AM')
		os.remove(os.path.join('git_repo', 'file'))
Example #37
0
File: common.py Project: tomef/vim
def branch(pl, segment_info, status_colors=False):
	'''Return the current VCS branch.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
	'''
	name = segment_info['getcwd']()
	repo = guess(path=name)
	if repo is not None:
		branch = repo.branch()
		scol = ['branch']
		if status_colors:
			status = tree_status(repo, pl)
			scol.insert(0, 'branch_dirty' if status and status.strip() else 'branch_clean')
		return [{
			'contents': branch,
			'highlight_group': scol,
		}]
Example #38
0
		def test_bzr(self):
			repo = guess(path=BZR_REPO)
			self.assertNotEqual(repo, None, 'No bzr repo found. Do you have bzr installed?')
			self.assertEqual(repo.branch(), 'test_powerline')
			self.assertEqual(repo.status(), None)
			with open(os.path.join(BZR_REPO, 'file'), 'w') as f:
				f.write('abc')
			self.assertEqual(repo.status(), ' U')
			self.assertEqual(repo.status('file'), '? ')
			call(['bzr', 'add', '.'], cwd=BZR_REPO, stdout=PIPE)
			self.assertEqual(repo.status(), 'D ')
			self.assertEqual(repo.status('file'), '+N')
			call(['bzr', 'commit', '-m', 'initial commit'], cwd=BZR_REPO, stdout=PIPE, stderr=PIPE)
			self.assertEqual(repo.status(), None)
			with open(os.path.join(BZR_REPO, 'file'), 'w') as f:
				f.write('def')
			self.assertEqual(repo.status(), 'D ')
			self.assertEqual(repo.status('file'), ' M')
			self.assertEqual(repo.status('notexist'), None)
			os.remove(os.path.join(BZR_REPO, 'file'))
Example #39
0
def branch(pl, status_colors=True):
    """Return the current VCS branch.

    :param bool status_colors:
        determines whether repository status will be used to determine highlighting. Default: True.

    Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.

    This version ignores untracked files.
    """
    repo = guess(path=os.path.abspath(os.getcwd()))
    if repo:
        branch = repo.branch()
        if status_colors:
            status = repo.status()
            status_elements = []
            # Keep display nice
            if status is not None:
                if "D" in status:
                    status_elements.append(symbols["plus_minus"])
                if "I" in status:
                    status_elements.append(symbols["envelope"])
                if "U" in status:
                    status_elements.append(symbols["big_u"])
                # Don't color for untracked files, just show U
                if status.strip() == "U":
                    status = None
            if "no branch" in branch or "DETACHED HEAD" in branch:
                branch_symbol = symbols["detached"]
                branch = "DETACHED"
            else:
                branch_symbol = symbols["branch"]
            return [
                {
                    "contents": "{} {} {}".format(branch_symbol, " ".join(status_elements), branch),
                    "highlight_group": ["branch_dirty" if status else "branch_clean", "branch"],
                }
            ]
        else:
            return branch
    return None
Example #40
0
def branch(pl, segment_info, create_watcher, status_colors=False):
    """Return the current working branch.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.

	Divider highlight group used: ``branch:divider``.
	"""
    name = segment_info["buffer"].name
    skip = not (name and (not vim_getbufoption(segment_info, "buftype")))
    if not skip:
        repo = guess(path=name, create_watcher=create_watcher)
        if repo is not None:
            branch = repo.branch()
            scol = ["branch"]
            if status_colors:
                status = tree_status(repo, pl)
                scol.insert(0, "branch_dirty" if status and status.strip() else "branch_clean")
            return [{"contents": branch, "highlight_group": scol, "divider_highlight_group": "branch:divider"}]
Example #41
0
def branch(pl, segment_info, status_colors=False, path=None):
    """Return the current VCS branch in specified directory.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.
	:param string path:
		determines which directory will be watched.
		current directory will be set if this is None. Default: None.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
	"""
    if path is None:
        path = segment_info["getcwd"]()
    repo = guess(path=path)
    if repo is not None:
        branch = repo.branch()
        scol = ["branch"]
        if status_colors:
            status = tree_status(repo, pl)
            scol.insert(0, "branch_dirty" if status and status.strip() else "branch_clean")
        return [{"contents": branch, "highlight_group": scol}]
Example #42
0
def file_vcs_status(pl, segment_info, create_watcher):
	'''Return the VCS status for this buffer.

	Highlight groups used: ``file_vcs_status``.
	'''
	name = buffer_name(segment_info)
	skip = not (name and (not vim_getbufoption(segment_info, 'buftype')))
	if not skip:
		repo = guess(path=name, create_watcher=create_watcher)
		if repo is not None:
			status = repo.status(os.path.relpath(name, repo.directory))
			if not status:
				return None
			status = status.strip()
			ret = []
			for status in status:
				ret.append({
					'contents': status,
					'highlight_groups': ['file_vcs_status_' + status, 'file_vcs_status'],
				})
			return ret
Example #43
0
def file_vcs_status(pl, segment_info):
	'''Return the VCS status for this buffer.

	Highlight groups used: ``file_vcs_status``.
	'''
	name = segment_info['buffer'].name
	skip = not (name and (not vim_getbufoption(segment_info, 'buftype')))
	if not skip:
		repo = guess(path=name)
		if repo is not None:
			status = repo.status(os.path.relpath(name, repo.directory))
			if not status:
				return None
			status = status.strip()
			ret = []
			for status in status:
				ret.append({
					'contents': status,
					'highlight_group': ['file_vcs_status_' + status, 'file_vcs_status'],
					})
			return ret
Example #44
0
def file_vcs_status(pl, segment_info):
	'''Return the VCS status for this buffer.

	Highlight groups used: ``file_vcs_status``.
	'''
	name = segment_info['buffer'].name
	skip = not (name and (not getbufvar(segment_info['bufnr'], '&buftype')))
	if not skip:
		repo = guess(path=name)
		if repo is not None:
			status = repo.status(os.path.relpath(name, repo.directory))
			if not status:
				return None
			status = status.strip()
			ret = []
			for status in status:
				ret.append({
					'contents': status,
					'highlight_group': ['file_vcs_status_' + status, 'file_vcs_status'],
					})
			return ret
Example #45
0
def repo_directory(pl, segment_info, create_watcher):
	name = buffer_name(segment_info)
	file_directory = vim_funcs['fnamemodify'](name, ':h')
	if not name:
		return None
	match = SCHEME_RE.match(name)
	if match:
		repo_directory = file_directory
	else:
		repo = guess(path=name, create_watcher=create_watcher)
		if repo is not None:
			directory_to_sub = vim_funcs['fnamemodify'](repo.directory, ':h:h') + os.sep
			repo_directory = repo.directory
		else:
			repo_directory = vim_funcs['fnamemodify'](name, ':h')
			directory_to_sub = vim_funcs['fnamemodify'](repo_directory, ':h:h')
			if directory_to_sub != '/':
				directory_to_sub = directory_to_sub + os.sep
		repo_directory = repo_directory[len(directory_to_sub):]
	repo_directory = repo_directory.decode(segment_info['encoding'], 'powerline_vim_strtrans_error')
	return [{
		'contents': repo_directory,
		'highlight_groups': ['repo_directory', 'file_name'],
		}]
Example #46
0
 def test_mercurial(self):
     if not use_mercurial:
         raise SkipTest('Mercurial is not available')
     create_watcher = get_fallback_create_watcher()
     repo = guess(path=HG_REPO, create_watcher=create_watcher)
     self.assertNotEqual(repo, None)
     self.assertEqual(repo.branch, 'default')
     self.assertEqual(repo.bookmark, None)
     self.assertEqual(repo.short, '-1')
     self.assertEqual(repo.summary, '')
     self.assertEqual(repo.name, 'tip')
     self.assertEqual(repo.status(), None)
     with open(os.path.join(HG_REPO, 'file'), 'w') as f:
         f.write('abc')
         f.flush()
         self.assertEqual(repo.status(), ' U')
         self.assertEqual(repo.status('file'), 'U')
         call(['hg', 'add', '.'], cwd=HG_REPO, stdout=PIPE)
         self.assertEqual(repo.status(), 'D ')
         self.assertEqual(repo.status('file'), 'A')
     call(['hg', 'commit', '-m', 'Abc\ndef'], cwd=HG_REPO, stdout=PIPE)
     self.assertEqual(repo.branch, 'default')
     self.assertEqual(repo.bookmark, None)
     self.assertEqual(repo.short, '0')
     self.assertEqual(repo.summary, 'Abc')
     self.assertEqual(repo.name, 'tip')
     call(['hg', 'bookmark', 'bm'], cwd=HG_REPO, stdout=PIPE)
     self.assertEqual(repo.branch, 'default')
     self.assertEqual(repo.bookmark, 'bm')
     self.assertEqual(repo.short, '0')
     self.assertEqual(repo.summary, 'Abc')
     self.assertEqual(repo.name, 'bm')
     call(['hg', 'rm', 'file'], cwd=HG_REPO, stdout=PIPE)
     call(['hg', 'commit', '-m', 'Ghi'], cwd=HG_REPO, stdout=PIPE)
     self.assertEqual(repo.branch, 'default')
     self.assertEqual(repo.bookmark, 'bm')
     self.assertEqual(repo.short, '1')
     self.assertEqual(repo.summary, 'Ghi')
     self.assertEqual(repo.name, 'bm')
     call(['hg', 'bookmark', '-i'], cwd=HG_REPO, stdout=PIPE)
     self.assertEqual(repo.branch, 'default')
     self.assertEqual(repo.bookmark, None)
     self.assertEqual(repo.short, '1')
     self.assertEqual(repo.summary, 'Ghi')
     self.assertEqual(repo.name, 'tip')
     call(['hg', 'update', '-r', '-2'], cwd=HG_REPO, stdout=PIPE)
     call(['hg', 'branch', 'b2'], cwd=HG_REPO, stdout=PIPE)
     call(['hg', 'rm', 'file'], cwd=HG_REPO, stdout=PIPE)
     call(['hg', 'commit', '-m', 'Jkl'], cwd=HG_REPO, stdout=PIPE)
     self.do_branch_rename_test(repo, 'b2')
     self.assertEqual(repo.bookmark, None)
     self.assertEqual(repo.short, '2')
     self.assertEqual(repo.summary, 'Jkl')
     self.assertEqual(repo.name, 'tip')
     call(['hg', 'update', 'default'], cwd=HG_REPO, stdout=PIPE)
     self.do_branch_rename_test(repo, 'default')
     self.assertEqual(repo.bookmark, None)
     self.assertEqual(repo.short, '1')
     self.assertEqual(repo.summary, 'Ghi')
     self.assertEqual(repo.name, 'default')
     call(['hg', 'update', '0'], cwd=HG_REPO, stdout=PIPE)
     self.assertEqual(repo.branch, 'default')
     self.assertEqual(repo.bookmark, None)
     self.assertEqual(repo.short, '0')
     self.assertEqual(repo.summary, 'Abc')
     self.assertEqual(repo.name, '0')
Example #47
0
    def test_bzr(self):
        if not use_bzr:
            raise SkipTest('Bazaar is not available')
        create_watcher = get_fallback_create_watcher()
        repo = guess(path=BZR_REPO, create_watcher=create_watcher)
        self.assertNotEqual(repo, None,
                            'No bzr repo found. Do you have bzr installed?')
        self.assertEqual(repo.branch(), 'test_powerline')
        self.assertEqual(repo.status(), None)
        with open(os.path.join(BZR_REPO, 'file'), 'w') as f:
            f.write('abc')
        self.assertEqual(repo.status(), ' U')
        self.assertEqual(repo.status('file'), '? ')
        call(['bzr', 'add', '-q', '.'], cwd=BZR_REPO, stdout=PIPE)
        self.assertEqual(repo.status(), 'D ')
        self.assertEqual(repo.status('file'), '+N')
        call(['bzr', 'commit', '-q', '-m', 'initial commit'], cwd=BZR_REPO)
        self.assertEqual(repo.status(), None)
        with open(os.path.join(BZR_REPO, 'file'), 'w') as f:
            f.write('def')
        self.assertEqual(repo.status(), 'D ')
        self.assertEqual(repo.status('file'), ' M')
        self.assertEqual(repo.status('notexist'), None)
        with open(os.path.join(BZR_REPO, 'ignored'), 'w') as f:
            f.write('abc')
        self.assertEqual(repo.status('ignored'), '? ')
        # Test changing the .bzrignore file should update status
        with open(os.path.join(BZR_REPO, '.bzrignore'), 'w') as f:
            f.write('ignored')
        self.assertEqual(repo.status('ignored'), None)
        # Test changing the dirstate file should invalidate the cache for
        # all files in the repo
        with open(os.path.join(BZR_REPO, 'file2'), 'w') as f:
            f.write('abc')
        call(['bzr', 'add', 'file2'], cwd=BZR_REPO, stdout=PIPE)
        call(['bzr', 'commit', '-q', '-m', 'file2 added'], cwd=BZR_REPO)
        with open(os.path.join(BZR_REPO, 'file'), 'a') as f:
            f.write('hello')
        with open(os.path.join(BZR_REPO, 'file2'), 'a') as f:
            f.write('hello')
        self.assertEqual(repo.status('file'), ' M')
        self.assertEqual(repo.status('file2'), ' M')
        call(['bzr', 'commit', '-q', '-m', 'multi'], cwd=BZR_REPO)
        self.assertEqual(repo.status('file'), None)
        self.assertEqual(repo.status('file2'), None)

        # Test changing branch
        call(['bzr', 'nick', 'branch1'],
             cwd=BZR_REPO,
             stdout=PIPE,
             stderr=PIPE)
        self.do_branch_rename_test(repo, 'branch1')

        # Test branch name/status changes when swapping repos
        for x in ('b1', 'b2'):
            d = os.path.join(BZR_REPO, x)
            os.mkdir(d)
            call(['bzr', 'init', '-q'], cwd=d)
            call(['bzr', 'nick', '-q', x], cwd=d)
            repo = guess(path=d, create_watcher=create_watcher)
            self.assertEqual(repo.branch(), x)
            self.assertFalse(repo.status())
            if x == 'b1':
                open(os.path.join(d, 'dirty'), 'w').close()
                self.assertTrue(repo.status())
        os.rename(os.path.join(BZR_REPO, 'b1'), os.path.join(BZR_REPO, 'b'))
        os.rename(os.path.join(BZR_REPO, 'b2'), os.path.join(BZR_REPO, 'b1'))
        os.rename(os.path.join(BZR_REPO, 'b'), os.path.join(BZR_REPO, 'b2'))
        for x, y in (('b1', 'b2'), ('b2', 'b1')):
            d = os.path.join(BZR_REPO, x)
            repo = guess(path=d, create_watcher=create_watcher)
            self.do_branch_rename_test(repo, y)
            if x == 'b1':
                self.assertFalse(repo.status())
            else:
                self.assertTrue(repo.status())
Example #48
0
    def test_git(self):
        create_watcher = get_fallback_create_watcher()
        repo = guess(path=GIT_REPO, create_watcher=create_watcher)
        self.assertNotEqual(repo, None)
        self.assertEqual(repo.branch, 'master')
        self.assertEqual(repo.status(), None)
        self.assertEqual(repo.status('file'), None)
        with open(os.path.join(GIT_REPO, 'file'), 'w') as f:
            f.write('abc')
            f.flush()
            self.assertEqual(repo.status(), '  U')
            self.assertEqual(repo.status('file'), '??')
            call(['git', 'add', '.'], cwd=GIT_REPO)
            self.assertEqual(repo.status(), ' I ')
            self.assertEqual(repo.status('file'), 'A ')
            f.write('def')
            f.flush()
            self.assertEqual(repo.status(), 'DI ')
            self.assertEqual(repo.status('file'), 'AM')
        os.remove(os.path.join(GIT_REPO, 'file'))
        # Test changing branch
        self.assertEqual(repo.branch, 'master')
        self.assertEqual(repo.bookmark, 'master')
        self.assertTrue(git_abbr_re.match(repo.short))
        self.assertEqual(repo.summary, 'Initial commit')
        self.assertEqual(repo.name, 'master')
        try:
            call(['git', 'branch', 'branch1'], cwd=GIT_REPO)
            call(['git', 'checkout', '-q', 'branch1'], cwd=GIT_REPO)
            self.do_branch_rename_test(repo, 'branch1')
            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, git_abbr_re.match)
        finally:
            call(['git', 'checkout', '-q', 'master'], cwd=GIT_REPO)
        # Test stashing
        self.assertEqual(repo.stash(), 0)

        def stash_save():
            with open(os.path.join(GIT_REPO, 'file'), 'w') as f:
                f.write('abc')
            return call(['git', 'stash', '-u'], cwd=GIT_REPO, stdout=PIPE)

        def stash_drop():
            return call(['git', 'stash', 'drop'], cwd=GIT_REPO, stdout=PIPE)

        def stash_list():
            return call(['git', 'stash', 'list'], cwd=GIT_REPO, stdout=PIPE)

        try:
            stash_save()
            self.assertEqual(repo.stash(), 1)
            stash_save()
            self.assertEqual(repo.stash(), 2)
            stash_drop()
            self.assertEqual(repo.stash(), 1)
            stash_drop()
            self.assertEqual(repo.stash(), 0)
        finally:
            while stash_list():
                stash_drop()