From e68c9987992567ba23d365130f2d402c5a5786e1 Mon Sep 17 00:00:00 2001 From: Shervin Sahba Date: Mon, 28 Oct 2019 22:08:51 -0700 Subject: [PATCH] Update git.py - added a check to see if branch exists Forgot to check if a branch existed! Fixed that. Now the script works in both .git repos and other directories. --- powerline_shell/segments/git.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/powerline_shell/segments/git.py b/powerline_shell/segments/git.py index 3591fea..435e0b0 100644 --- a/powerline_shell/segments/git.py +++ b/powerline_shell/segments/git.py @@ -67,15 +67,17 @@ class Segment(ThreadedSegment): def run(self): self.stats, self.branch = build_stats() - # Abbreviates master branch to M - if self.powerline.segment_conf("git", "master_is_M"): - if self.branch == "master": - self.branch = "M" + if self.branch: + # Abbreviates master branch to M + if self.powerline.segment_conf("git", "master_is_M"): + if self.branch == "master": + self.branch = "M" - # Truncates branch length - branch_max_length = self.powerline.segment_conf("git", "branch_max_length", -1) - if len(self.branch) > branch_max_length : - self.branch = self.branch[:branch_max_length] + u'\u2026' + # Truncates branch length + branch_max_length = self.powerline.segment_conf("git", "branch_max_length", -1) + if len(self.branch) > branch_max_length : + self.branch = self.branch[:branch_max_length] + u'\u2026' + def add_to_powerline(self): self.join()