mirror of
https://github.com/davidosomething/git-my.git
synced 2026-09-10 07:06:20 -04:00
shellcheck fixes
This commit is contained in:
parent
23b27d75e5
commit
c46dd14ac2
|
|
@ -1,4 +1,4 @@
|
||||||
# git-my v1.1.0
|
# git-my
|
||||||
|
|
||||||
Lists all of a user's branches, including local and remote, and shows:
|
Lists all of a user's branches, including local and remote, and shows:
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@ Lists all of a user's branches, including local and remote, and shows:
|
||||||
- if a local branch is up-to-date with a specified branch
|
- if a local branch is up-to-date with a specified branch
|
||||||
|
|
||||||
| Name | Link |
|
| Name | Link |
|
||||||
| ---- | ---- |
|
| ------------- | -------- |
|
||||||
| Project Home: | [https://github.com/davidosomething/git-my](https://github.com/davidosomething/git-my)
|
| Project Home: | [https://github.com/davidosomething/git-my](https://github.com/davidosomething/git-my)
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
|
||||||
53
git-my
53
git-my
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# git-my v1.1.0
|
# git-my v1.1.1
|
||||||
#
|
#
|
||||||
# Lists a user's remote branches and shows if it was merged
|
# Lists a user's remote branches and shows if it was merged
|
||||||
# and/or available locally
|
# and/or available locally
|
||||||
|
|
@ -13,19 +13,19 @@
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
# _check_in_repository
|
# is_repository
|
||||||
#
|
#
|
||||||
# Exits with error if not a git repository
|
# Exits with error if not a git repository
|
||||||
#
|
#
|
||||||
_check_in_repository() {
|
is_repository() {
|
||||||
git rev-parse --git-dir >/dev/null 2>&1
|
git rev-parse --git-dir >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
# _get_local_branches
|
# get_local_branches
|
||||||
#
|
#
|
||||||
# Proper way to get a porcelain list of local branches for shell script use
|
# Proper way to get a porcelain list of local branches for shell script use
|
||||||
#
|
#
|
||||||
_get_local_branches() {
|
get_local_branches() {
|
||||||
local fmt
|
local fmt
|
||||||
local cmd_get_local_branches
|
local cmd_get_local_branches
|
||||||
|
|
||||||
|
|
@ -42,13 +42,13 @@ _get_local_branches() {
|
||||||
eval "$cmd_get_local_branches"
|
eval "$cmd_get_local_branches"
|
||||||
}
|
}
|
||||||
|
|
||||||
# _get_everyones_remotes
|
# get_everyones_remotes
|
||||||
#
|
#
|
||||||
# Get porcelain list of all remote branches
|
# Get porcelain list of all remote branches
|
||||||
#
|
#
|
||||||
# @TODO support remote_name (currently origin)
|
# @TODO support remote_name (currently origin)
|
||||||
#
|
#
|
||||||
_get_everyones_remotes() {
|
get_everyones_remotes() {
|
||||||
local fmt
|
local fmt
|
||||||
local cmd_everyones_remotes
|
local cmd_everyones_remotes
|
||||||
|
|
||||||
|
|
@ -71,12 +71,12 @@ _get_everyones_remotes() {
|
||||||
eval "$cmd_everyones_remotes"
|
eval "$cmd_everyones_remotes"
|
||||||
}
|
}
|
||||||
|
|
||||||
# _get_merged_remote_branches
|
# get_merged_remote_branches
|
||||||
#
|
#
|
||||||
# @param string optional remote to list merged branches of. Defaults to
|
# @param string optional remote to list merged branches of. Defaults to
|
||||||
# "origin/master"
|
# "origin/master"
|
||||||
# @output names of remote branches that are merged into given branch
|
# @output names of remote branches that are merged into given branch
|
||||||
_get_merged_remote_branches() {
|
get_merged_remote_branches() {
|
||||||
local remote
|
local remote
|
||||||
local remote_name
|
local remote_name
|
||||||
#local remote_refname
|
#local remote_refname
|
||||||
|
|
@ -103,12 +103,12 @@ _get_merged_remote_branches() {
|
||||||
echo "$stripped_branchnames"
|
echo "$stripped_branchnames"
|
||||||
}
|
}
|
||||||
|
|
||||||
# _filter_mine
|
# filter_mine
|
||||||
#
|
#
|
||||||
# @param git_user
|
# @param git_user
|
||||||
# @param branchnames
|
# @param branchnames
|
||||||
# @output branchnames owned by current git user
|
# @output branchnames owned by current git user
|
||||||
_filter_mine() {
|
filter_mine() {
|
||||||
local git_user
|
local git_user
|
||||||
local branchnames
|
local branchnames
|
||||||
git_user=$1
|
git_user=$1
|
||||||
|
|
@ -122,13 +122,13 @@ _filter_mine() {
|
||||||
echo "$my_remotes" | grep -v "HEAD" | awk -F'\t' '{ print $2 }'
|
echo "$my_remotes" | grep -v "HEAD" | awk -F'\t' '{ print $2 }'
|
||||||
}
|
}
|
||||||
|
|
||||||
# _merge_lists
|
# merge_lists
|
||||||
#
|
#
|
||||||
# Convert two lists to bash arrays, merge them, sort them
|
# Convert two lists to bash arrays, merge them, sort them
|
||||||
#
|
#
|
||||||
# @param list1
|
# @param list1
|
||||||
# @param list2
|
# @param list2
|
||||||
_merge_lists() {
|
merge_lists() {
|
||||||
local l1
|
local l1
|
||||||
local l2
|
local l2
|
||||||
l1=$(echo "$1" | awk '{$1=$1};1')
|
l1=$(echo "$1" | awk '{$1=$1};1')
|
||||||
|
|
@ -145,14 +145,14 @@ _merge_lists() {
|
||||||
echo "${intersect[@]}"
|
echo "${intersect[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# _decorate_merged
|
# decorate_merged
|
||||||
#
|
#
|
||||||
# @param string my_branches list of remote branch names owned by me
|
# @param string my_branches list of remote branch names owned by me
|
||||||
# @param string local_branches list of local branch names
|
# @param string local_branches list of local branch names
|
||||||
# @param string merged_remote_branches list of all remote branch names merged
|
# @param string merged_remote_branches list of all remote branch names merged
|
||||||
# into another branch
|
# into another branch
|
||||||
# @output table of branch names and status
|
# @output table of branch names and status
|
||||||
_decorate_merged() {
|
decorate_merged() {
|
||||||
local my_branches
|
local my_branches
|
||||||
readarray -t my_branches <<< "$(echo "$1" | tr ' ' '\n' )"
|
readarray -t my_branches <<< "$(echo "$1" | tr ' ' '\n' )"
|
||||||
|
|
||||||
|
|
@ -201,11 +201,11 @@ _decorate_merged() {
|
||||||
"$is_local" "$is_tracked" "$is_merged" "$branchname")
|
"$is_local" "$is_tracked" "$is_merged" "$branchname")
|
||||||
|
|
||||||
if [ $zebra = 0 ]; then
|
if [ $zebra = 0 ]; then
|
||||||
echo -en ${normal}
|
echo -en "${normal}"
|
||||||
printf "\e[48;5;0m%s %s\n" "$decorated" "$clreol"
|
printf "\e[48;5;0m%s %s\n" "$decorated" "$clreol"
|
||||||
zebra=1
|
zebra=1
|
||||||
else
|
else
|
||||||
echo -en ${normal}
|
echo -en "${normal}"
|
||||||
printf "\e[48;5;236m%s %s" "$decorated" "$clreol"
|
printf "\e[48;5;236m%s %s" "$decorated" "$clreol"
|
||||||
if [[ "$i" != "$last" ]]; then printf "\n"; fi
|
if [[ "$i" != "$last" ]]; then printf "\n"; fi
|
||||||
zebra=0
|
zebra=0
|
||||||
|
|
@ -215,13 +215,14 @@ _decorate_merged() {
|
||||||
printf "\e[48;5;0m\n"
|
printf "\e[48;5;0m\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
_main() {
|
main() {
|
||||||
local decorated
|
local decorated
|
||||||
local everyones_remotes
|
local everyones_remotes
|
||||||
local git_remote
|
local git_remote
|
||||||
local git_user
|
local git_user
|
||||||
local local_branches
|
local local_branches
|
||||||
local merged_remote_branches
|
local merged_remote_branches
|
||||||
|
local my_branches
|
||||||
local my_remotes
|
local my_remotes
|
||||||
|
|
||||||
local remote=${1:-"origin/master"}
|
local remote=${1:-"origin/master"}
|
||||||
|
|
@ -233,11 +234,11 @@ _main() {
|
||||||
|
|
||||||
git_user=$(git config --get user.name)
|
git_user=$(git config --get user.name)
|
||||||
git_remote=$(git config --get "remote.${remote_name}.url")
|
git_remote=$(git config --get "remote.${remote_name}.url")
|
||||||
everyones_remotes=$(_get_everyones_remotes "$remote_name")
|
everyones_remotes=$(get_everyones_remotes "$remote_name")
|
||||||
my_remotes=$(_filter_mine "$git_user" "$everyones_remotes")
|
my_remotes=$(filter_mine "$git_user" "$everyones_remotes")
|
||||||
merged_remote_branches=$(_get_merged_remote_branches "$remote_name/$remote_ref")
|
merged_remote_branches=$(get_merged_remote_branches "$remote_name/$remote_ref")
|
||||||
local_branches=$(_get_local_branches)
|
local_branches=$(get_local_branches)
|
||||||
my_branches=$(_merge_lists "$my_remotes" "$local_branches")
|
my_branches=$(merge_lists "$my_remotes" "$local_branches")
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "branches owned by user: $git_user"
|
echo "branches owned by user: $git_user"
|
||||||
|
|
@ -245,15 +246,15 @@ _main() {
|
||||||
echo "in remote repository: $git_remote"
|
echo "in remote repository: $git_remote"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
_decorate_merged "$my_branches" "$local_branches" "$merged_remote_branches"
|
decorate_merged "$my_branches" "$local_branches" "$merged_remote_branches"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! _check_in_repository ; then
|
if ! is_repository; then
|
||||||
echo "This is not a git repository."
|
echo "This is not a git repository."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_main "$@"
|
main "$@"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue