mirror of
https://github.com/paulirish/git-recent.git
synced 2026-09-10 07:26:16 -04:00
DRY up branchname definition
This commit is contained in:
parent
f8ec6b624b
commit
61a89ac1cb
18
git-recent
18
git-recent
|
|
@ -29,20 +29,22 @@ fi
|
|||
|
||||
# Colorized hash, author, date, then commit subject followed by commit message body (wrapped and indented).
|
||||
commits_format="%C(red bold)%h %C(bold blue)%an %C(bold green)%ad %Creset%s%w(0,4,4)%+b%w(0,0,0)"
|
||||
# commits_format='%h (%>(16)%ad %an) %s%w(0,4,4)%+b%w(0,0,0)'
|
||||
|
||||
# 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}')
|
||||
|
||||
# the cut drops anything after the branch name, like the Chromium link. These commands need to work in all shells (bash, fish, etc)
|
||||
uniqcommits_cmd="git log --date=human --color=always --format='$commits_format' --no-merges $diff_base..\$(echo {1} | cut -d' ' -f1)"
|
||||
diffbranch_cmd="git diff --color=always $diff_base...\$(echo {1} | cut -d' ' -f1)"
|
||||
# Extract branch name (without any trailing text, like the Chromium link)
|
||||
define_branchname="branchname=\\\$(echo {1} | cut -d' ' -f1)"
|
||||
uniqcommits_cmd="sh -c \"$define_branchname; git log --date=human --color=always --format='$commits_format' --no-merges $diff_base..\\\$branchname\""
|
||||
|
||||
# Progressive enhancement if you have delta or diff-so-fancy
|
||||
if command -v delta >/dev/null 2>&1; then
|
||||
diffbranch_cmd="$diffbranch_cmd | delta"
|
||||
if command -v deltaz >/dev/null 2>&1; then
|
||||
diffbranch_cmd="sh -c \"$define_branchname; git diff --color=always $diff_base...\\\$branchname | delta\""
|
||||
elif command -v diff-so-fancy >/dev/null 2>&1; then
|
||||
diffbranch_cmd="$diffbranch_cmd | diff-so-fancy"
|
||||
diffbranch_cmd="sh -c \"$define_branchname; git diff --color=always $diff_base...\\\$branchname | diff-so-fancy\""
|
||||
else
|
||||
diffbranch_cmd="sh -c \"$define_branchname; git diff --color=always $diff_base...\\\$branchname\""
|
||||
fi
|
||||
|
||||
# Copy to clipboard, variants for mac/linux
|
||||
|
|
@ -73,7 +75,7 @@ NC='\033[0m' # No Color
|
|||
# - https://github.com/junegunn/fzf/wiki/Examples-(fish)#git
|
||||
# - https://github.com/junegunn/fzf-git.sh (intense.)
|
||||
|
||||
# If there's a GIT_RECENT_QUERY environment variable, use it for non-interactive filtering. (Primarily added for testing.)
|
||||
# If there's a GIT_RECENT_QUERY environment variable, use it for non-interactive filtering. (Primarily added for testing: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/g/git-recent.rb#L41-L46)
|
||||
filterarg=${GIT_RECENT_QUERY:+"--filter=$GIT_RECENT_QUERY"}
|
||||
|
||||
# Chromium hackers may want reference to their relevant CL.
|
||||
|
|
|
|||
Loading…
Reference in a new issue