refactor: extract _forgit_git_log from _forgit_log

This commit is contained in:
sandroid 2026-03-12 21:37:10 +01:00 committed by sandr01d
parent 30aff90e30
commit 41912c2907
2 changed files with 41 additions and 8 deletions

View file

@ -231,10 +231,22 @@ _forgit_log_enter() {
"${FORGIT}" show "${sha}" "$@"
}
_forgit_git_log() {
local graph log_format
log_format=$1
shift
graph=()
[[ $_forgit_log_graph_enable == true ]] && graph=(--graph)
_forgit_log_git_opts=()
_forgit_parse_array _forgit_log_git_opts "$FORGIT_LOG_GIT_OPTS"
git log "${graph[@]}" --color=always --format="$log_format" "${_forgit_log_git_opts[@]}" "$@" |
_forgit_emojify
}
# git commit viewer
_forgit_log() {
_forgit_inside_work_tree || return 1
local opts graph quoted_files log_format
local opts quoted_files log_format
quoted_files=$(_forgit_quote_files "$@")
opts="
$FORGIT_FZF_DEFAULT_OPTS
@ -244,14 +256,8 @@ _forgit_log() {
--preview=\"$FORGIT preview log_preview {} $quoted_files\"
$FORGIT_LOG_FZF_OPTS
"
graph=()
[[ $_forgit_log_graph_enable == true ]] && graph=(--graph)
log_format=${FORGIT_GLO_FORMAT:-$_forgit_log_format}
_forgit_log_git_opts=()
_forgit_parse_array _forgit_log_git_opts "$FORGIT_LOG_GIT_OPTS"
git log "${graph[@]}" --color=always --format="$log_format" "${_forgit_log_git_opts[@]}" "$@" |
_forgit_emojify |
FZF_DEFAULT_OPTS="$opts" fzf
_forgit_git_log "$log_format" "$@" | FZF_DEFAULT_OPTS="$opts" fzf
fzf_exit_code=$?
# exit successfully on 130 (ctrl-c/esc)
[[ $fzf_exit_code == 130 ]] && return 0

27
tests/log.test.sh Normal file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
function set_up_before_script() {
# disable log graph to remove the asterisk from the output
export FORGIT_LOG_GRAPH_ENABLE='false'
source bin/git-forgit
# ignore global git config files
export GIT_CONFIG_SYSTEM=/dev/null
export GIT_CONFIG_GLOBAL=/dev/null
# create a new git repository in a temp directory
cd "$(bashunit::temp_dir)" || return 1
git init --quiet
git config user.email "test@example.com"
git config user.name "Test User"
# create an initial commit so we have a valid repo
git commit --allow-empty -qm "Initial commit"
}
function test_forgit_git_log() {
local output
# set log format to '%s' so we don't have to match the commit hash
output=$(_forgit_git_log '%s' 2>&1 | sed 's/^[0-9a-f] //')
assert_same "Initial commit" "$output"
}