mirror of
https://github.com/paulirish/git-recent.git
synced 2026-09-10 07:26:16 -04:00
chromium cl status integration (#33)
This commit is contained in:
parent
d5f63cf328
commit
73e40691c6
41
git-recent
41
git-recent
|
|
@ -27,16 +27,15 @@ fi
|
|||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
|
||||
branches_format="%(color:yellow)%(refname:short)%(color:reset)"
|
||||
commits_format="%C(red bold)%h %C(bold blue)%an %C(bold green)%ad %Creset%s"
|
||||
|
||||
# The HEAD of the primary branch (eg main or master or w/e), for diffing.
|
||||
# TODO: some branch mgmt approaches don't work well with this. And may prefer `git log --pretty=format:%H --merges -n 1`. See https://github.com/paulirish/git-recent/issues/28
|
||||
diff_base=$(cat $(git rev-parse --show-cdup).git/refs/remotes/origin/HEAD | awk '{print $2}')
|
||||
|
||||
uniqcommits_cmd="git log --date=human --color=always --format='$commits_format' --no-merges $diff_base..{1}"
|
||||
uniqcommits_cmd="branch_name=\$(echo {1} | cut -d' ' -f1) git log --date=human --color=always --format='$commits_format' --no-merges $diff_base..\$branch_name"
|
||||
|
||||
diffbranch_cmd="git diff --color=always $diff_base...{}"
|
||||
diffbranch_cmd="branch_name=\$(echo {1} | cut -d' ' -f1) git diff --color=always $diff_base...\$branch_name"
|
||||
# Progressive enhancement if you have delta or diff-so-fancy
|
||||
if command -v delta >/dev/null 2>&1; then
|
||||
diffbranch_cmd="$diffbranch_cmd | delta"
|
||||
|
|
@ -56,8 +55,16 @@ elif command -v xsel >/dev/null; then
|
|||
copy_cmd="printf '%s' {} | xsel --clipboard"
|
||||
fi
|
||||
|
||||
YELLOW='\033[0;33m'
|
||||
DIM='\033[2m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# if show_cl passed then also run git cl status. (chromium repos)
|
||||
[[ "$1" == "--cl" || "$1" == "-cl" ]] && show_cl=true || show_cl=false
|
||||
|
||||
# if extra arg passed (eg `git recent remotename`), then list those remote branches, rather than local ones
|
||||
[[ -n "$1" ]] && heads="refs/remotes/$1" || heads="refs/heads"
|
||||
[[ -n "$1" && "$show_cl" != true ]] && heads="refs/remotes/$1" || heads="refs/heads"
|
||||
|
||||
|
||||
# fzf git inspiration:
|
||||
# - https://github.com/junegunn/fzf/wiki/Examples#git
|
||||
|
|
@ -67,9 +74,22 @@ fi
|
|||
# If there's a GIT_RECENT_QUERY environment variable, use it for non-interactive filtering. (Primarily added for testing.)
|
||||
filterarg=${GIT_RECENT_QUERY:+"--filter=$GIT_RECENT_QUERY"}
|
||||
|
||||
# Chromium hackers may want reference to their relevant CL.
|
||||
CL_STATUS=$([ "$show_cl" = true ] && git cl status --fast --no-branch-color | grep 'https://' | sed 's| (.*||')
|
||||
|
||||
_browse_branches() {
|
||||
git for-each-ref --color=always --sort=-authordate "$heads" --format="$branches_format" \
|
||||
| fzf \
|
||||
git for-each-ref --sort=-authordate "$heads" --format="%(refname:short)" \
|
||||
| while read -r branch_name; do
|
||||
if [ "$show_cl" != true ]; then
|
||||
printf "$YELLOW%s$NC\n" "$branch_name"
|
||||
continue
|
||||
fi
|
||||
review_url=$(echo "$CL_STATUS" | grep -E "\b${branch_name}\b" | grep -o -E 'https://.*' | sed 's|https://||')
|
||||
# Using fancy integrated hyperlinks: https://iterm2.com/feature-reporting/Hyperlinks_in_Terminal_Emulators.html
|
||||
# TODO: maybe get rid of the crrev.com/c/ text as the link?
|
||||
printf "$YELLOW%s $DIM\033]8;;%s\a%s\033]8;;\a$NC\n" "$branch_name" "https://$review_url" "$review_url"
|
||||
done \
|
||||
| fzf \
|
||||
$filterarg --ansi -- --layout=reverse --multi --height=90% --min-height=20 \
|
||||
--border-label-pos=2 --border-label '🌲 Branches' --border \
|
||||
--no-hscroll --no-multi \
|
||||
|
|
@ -80,12 +100,13 @@ _browse_branches() {
|
|||
--bind "ctrl-y:execute-silent($copy_cmd)" \
|
||||
--bind "ctrl-o:preview:$diffbranch_cmd"
|
||||
}
|
||||
chosen_branch="$(_browse_branches)"
|
||||
line_count=$(printf "%s" "$chosen_branch" | wc -l)
|
||||
output="$(_browse_branches)"
|
||||
line_count=$(printf "%s" "$output" | wc -l)
|
||||
|
||||
if [[ -n "$chosen_branch" ]] && (( line_count == 0 )); then
|
||||
if [[ -n "$output" ]] && (( line_count == 0 )); then
|
||||
chosen_branch=$(echo "$output" | cut -d' ' -f1)
|
||||
echo git checkout "$chosen_branch"
|
||||
git checkout "$chosen_branch"
|
||||
else
|
||||
echo "$chosen_branch"
|
||||
echo "$output"
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in a new issue