Skip to content

Commit 5922547

Browse files
authored
Sort branch lists alphabetically (#1576)
1 parent 756f83c commit 5922547

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Services/MonitoredRepository.vala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,17 @@ namespace Scratch.Services {
157157
return "";
158158
}
159159

160+
//Returns an alphabetically sorted list of local branch names
160161
public unowned List<string> get_local_branches () {
161162
unowned List<string> branches = null;
162163
try {
163164
var branch_enumerator = git_repo.enumerate_branches (Ggit.BranchType.LOCAL);
164165
foreach (Ggit.Ref branch_ref in branch_enumerator) {
165166
if (branch_ref is Ggit.Branch) {
166-
branches.append (((Ggit.Branch)branch_ref).get_name ());
167+
branches.insert_sorted (
168+
((Ggit.Branch)branch_ref).get_name (),
169+
string.collate
170+
);
167171
}
168172
}
169173
} catch (Error e) {
@@ -173,6 +177,7 @@ namespace Scratch.Services {
173177
return branches;
174178
}
175179

180+
//Returns an alphabetically sorted list of remote branch names
176181
public unowned List<string> get_remote_branches () {
177182
unowned List<string> branch_names = null;
178183
try {
@@ -183,7 +188,10 @@ namespace Scratch.Services {
183188
if (!remote_name.has_suffix ("HEAD") &&
184189
!has_local_branch_name (remote_name.substring (ORIGIN_PREFIX.length))) {
185190

186-
branch_names.append (branch_ref.get_shorthand ());
191+
branch_names.insert_sorted (
192+
branch_ref.get_shorthand (),
193+
string.collate
194+
);
187195
}
188196

189197
remote_branch_ref_list.append (branch_ref);

0 commit comments

Comments
 (0)