Fix sorting order

This commit is contained in:
Willa Drengwitz
2018-08-31 08:58:23 -04:00
parent a3ff809cbe
commit d0c8329137
2 changed files with 18 additions and 15 deletions

View File

@@ -68,8 +68,8 @@ function git_index() {
elif [ "$1" = "--list" ] || [ "$1" = "-l" ]; then elif [ "$1" = "--list" ] || [ "$1" = "-l" ]; then
echo -e "$_bld_col$(_git_index_count)$_txt_col Git repositories in $_bld_col$GIT_REPO_DIR$_txt_col:\n" echo -e "$_bld_col$(_git_index_count)$_txt_col Git repositories in $_bld_col$GIT_REPO_DIR$_txt_col:\n"
for repo in $(_git_index_dirs_without_home); do for repo in $(_git_index_dirs_without_home); do
echo $(basename $repo) : $repo echo $(basename $repo | sed "s/ /_/g") : $repo
done | sort | column -t -s ':' done | sort -t ":" -k1,1 | column -t -s ':'
elif [ "$1" = "--count-by-host" ]; then elif [ "$1" = "--count-by-host" ]; then
echo -e "=== Producing a report of the number of repos per host...\n" echo -e "=== Producing a report of the number of repos per host...\n"
_git_index_batch_cmd git remote -v | \grep "origin.*(fetch)" | _git_index_batch_cmd git remote -v | \grep "origin.*(fetch)" |
@@ -148,8 +148,8 @@ function _rebuild_git_index() {
# Get repos from src dir and custom dirs, then sort by basename # Get repos from src dir and custom dirs, then sort by basename
IFS=$'\n' IFS=$'\n'
for repo in $(echo -e "$(_find_git_repos)\n$(echo $GIT_REPOS | sed "s/:/\\\\n/g")"); do for repo in $(echo -e "$(_find_git_repos)\n$(echo $GIT_REPOS | sed "s/:/\\\\n/g")"); do
echo $(basename $repo | sed "s/ /_/g") $repo echo $(basename $repo | sed "s/ /_/g"):$repo
done | sort | cut -d " " -f2- >| "$GIT_REPO_DIR/.git_index" done | sort -t ":" -k1,1 | cut -d ":" -f2- >| "$GIT_REPO_DIR/.git_index"
unset IFS unset IFS
if [ "$1" != "--silent" ]; then if [ "$1" != "--silent" ]; then

View File

@@ -94,16 +94,19 @@ test_repo_index_command() {
git_index --rebuild > /dev/null git_index --rebuild > /dev/null
# Test that all repos are detected, and sorted alphabetically # Test that all repos are detected, and sorted alphabetically
assertIncludes "$(index_no_newlines)" "bitbucket.*\ assertIncludes "$(index_no_newlines)" $(
blue_submodule.*\ cat <<EXPECT | sort -t "." -k1,1 | tr --delete '\n' | awk '{print ".*"$1}'
github.*\ bitbucket.*
green_submodule.*\ blue_submodule.*
red_submodule.*\ github.*
source_forge.*\ green_submodule.*
submodules_everywhere.*\ red_submodule.*
test_repo_11.*\ source_forge.*
test_repo_1" submodules_everywhere.*
test_repo_11.*
test_repo_1.*
EXPECT
)
} }
test_check_git_index() { test_check_git_index() {
@@ -141,7 +144,7 @@ test_git_index_changing_directory() {
git_index "_submod"; assertEquals "$GIT_REPO_DIR/submodules_everywhere/very/nested/directory/blue_submodule" "$PWD" git_index "_submod"; assertEquals "$GIT_REPO_DIR/submodules_everywhere/very/nested/directory/blue_submodule" "$PWD"
git_index "test_repo_1"; assertEquals "/tmp/test_repo_1" "$PWD" git_index "test_repo_1"; assertEquals "/tmp/test_repo_1" "$PWD"
git_index "test_repo_11"; assertEquals "/tmp/test_repo_11" "$PWD" git_index "test_repo_11"; assertEquals "/tmp/test_repo_11" "$PWD"
git_index "test_repo_"; assertEquals "/tmp/test_repo_11" "$PWD" git_index "test_repo_"; assertEquals "/tmp/test_repo_1" "$PWD"
git_index "github/videos/octocat/live_action"; assertEquals "$GIT_REPO_DIR/github/videos/octocat/live_action" "$PWD" git_index "github/videos/octocat/live_action"; assertEquals "$GIT_REPO_DIR/github/videos/octocat/live_action" "$PWD"
} }