Skip to content

Commit

Permalink
Sort branches by recent commited (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetithefoot authored and randy3k committed Apr 13, 2017
1 parent af6654a commit 4d09a75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions GitSavvy.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@
// to use columns globally, --no-columns should be added here.
// "branch": ["--no-columns"]
},

/*
Prints branches sorted by recent commit (works with git 2.7.0+)
https://www.kernel.org/pub/software/scm/git/docs/git-branch.html
Change this to `true` to sort branches by recent.
Change this to `false` to sort branches by alphanumeric.
*/
"sort_by_recent_in_branch_dashboard": false,

/*
Set this to `true` to display remotes in the branch dashboard by default.
Expand Down
4 changes: 2 additions & 2 deletions core/git_mixins/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

class BranchesMixin():

def get_branches(self):
def get_branches(self, sort_by_recent=False):
"""
Return a list of all local and remote branches.
"""
stdout = self.git("branch", "-a", "-vv", "--no-abbrev", "--no-color")
stdout = self.git("branch", "-a", "-vv", "--no-abbrev", "--no-color", "--sort=-committerdate" if sort_by_recent else None)
return (branch
for branch in (self._parse_branch_line(self, line) for line in stdout.split("\n"))
if branch)
Expand Down
5 changes: 4 additions & 1 deletion core/interfaces/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def title(self):
return "BRANCHES: {}".format(os.path.basename(self.repo_path))

def pre_render(self):
self._branches = tuple(self.get_branches())
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
sort_by_recent = savvy_settings.get("sort_by_recent_in_branch_dashboard")
self._branches = tuple(self.get_branches(sort_by_recent))


def on_new_dashboard(self):
self.view.run_command("gs_branches_navigate_branch")
Expand Down

0 comments on commit 4d09a75

Please sign in to comment.