Skip to content

Commit

Permalink
feat: add flag parsing for git worktree lock
Browse files Browse the repository at this point in the history
  • Loading branch information
suft committed Dec 18, 2024
1 parent bcdd3a1 commit a0dc127
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions bin/git-forgit
Original file line number Diff line number Diff line change
Expand Up @@ -1050,12 +1050,23 @@ _forgit_git_worktree_lock() {

_forgit_worktree_lock() {
_forgit_inside_work_tree || _forgit_inside_git_dir || return 1

local tree opts reason
if [[ $# -ne 0 ]]; then
git worktree lock "$@"
worktree_lock_status=$?
return $worktree_lock_status
if [[ "$1" == "--reason" ]]; then
if [[ -z "$2" ]]; then
_forgit_warn "Option \`--reason' requires a value"
return 1
fi
reason="$2"
shift 2
fi

if [[ $# -eq 0 ]] || _forgit_contains_non_flags "$@"; then
git worktree lock "$@" --reason "$reason"
return $?
fi
fi
local tree opts

opts="
$FORGIT_FZF_DEFAULT_OPTS
Expand All @@ -1066,7 +1077,12 @@ _forgit_worktree_lock() {

tree=$(git worktree list | grep -vE "\(bare\)|locked" | awk '{print $1}' | FZF_DEFAULT_OPTS="$opts" fzf)
[[ -z "$tree" ]] && return 1
_forgit_git_worktree_lock "$tree"

if [[ -z "$reason" ]]; then
_forgit_git_worktree_lock "$tree"
else
_forgit_git_worktree_lock "$tree" --reason "$reason"
fi
}

_forgit_git_worktree_remove() {
Expand Down

0 comments on commit a0dc127

Please sign in to comment.