support case insensitive branch names

This commit is contained in:
Jesse Duffield 2018-08-11 16:11:17 +10:00
parent 9626ebdf35
commit 2dba6f6733
4 changed files with 44 additions and 3 deletions

View file

@ -66,11 +66,19 @@ func (b *branchListBuilder) appendNewBranches(finalBranches, newBranches, existi
if included == branchIncluded(newBranch.Name, existingBranches) { if included == branchIncluded(newBranch.Name, existingBranches) {
finalBranches = append(finalBranches, newBranch) finalBranches = append(finalBranches, newBranch)
} }
} }
return finalBranches return finalBranches
} }
func sanitisedReflogName(reflogBranch Branch, safeBranches []Branch) string {
for _, safeBranch := range safeBranches {
if strings.ToLower(safeBranch.Name) == strings.ToLower(reflogBranch.Name) {
return safeBranch.Name
}
}
return reflogBranch.Name
}
func (b *branchListBuilder) build() []Branch { func (b *branchListBuilder) build() []Branch {
branches := make([]Branch, 0) branches := make([]Branch, 0)
head := b.obtainCurrentBranch() head := b.obtainCurrentBranch()
@ -80,6 +88,9 @@ func (b *branchListBuilder) build() []Branch {
} }
reflogBranches := b.obtainReflogBranches() reflogBranches := b.obtainReflogBranches()
reflogBranches = uniqueByName(append([]Branch{head}, reflogBranches...)) reflogBranches = uniqueByName(append([]Branch{head}, reflogBranches...))
for i, reflogBranch := range reflogBranches {
reflogBranches[i].Name = sanitisedReflogName(reflogBranch, safeBranches)
}
branches = b.appendNewBranches(branches, reflogBranches, safeBranches, true) branches = b.appendNewBranches(branches, reflogBranches, safeBranches, true)
branches = b.appendNewBranches(branches, safeBranches, branches, false) branches = b.appendNewBranches(branches, safeBranches, branches, false)

View file

@ -0,0 +1,30 @@
#!/bin/bash
# this script makes a repo with lots of commits
# call this command from the test directory:
# ./lots_of_commits.sh; cd testrepo; gg; cd ..
# -e means exit if something fails
# -x means print out simple commands before running them
set -ex
reponame="case_insensitive_checkouts"
rm -rf ${reponame}
mkdir ${reponame}
cd ${reponame}
git init
touch foo
git add foo
git commit -m "init"
git branch -a
git branch test
git branch TEST
git checkout TEST
git checkout TeST
git checkout TesT
git checkout TEsT
git branch -a

View file

@ -9,7 +9,7 @@
# -x means print out simple commands before running them # -x means print out simple commands before running them
set -ex set -ex
reponame="testrepo" reponame="lots_of_commits"
rm -rf ${reponame} rm -rf ${reponame}
mkdir ${reponame} mkdir ${reponame}

View file

@ -10,7 +10,7 @@
# -x means print out simple commands before running them # -x means print out simple commands before running them
set -ex set -ex
reponame="testrepo" reponame="unicode_characters"
rm -rf ${reponame} rm -rf ${reponame}
mkdir ${reponame} mkdir ${reponame}