support checkout commits

pull/3/head
kevin zhuang 4 years ago
parent fe9ee43418
commit 0534c5cef8

@ -31,15 +31,22 @@ function usage() {
all_files=""
branch=""
commits=""
while getopts ":hab" opt
while getopts ":habc" opt
do
case "$opt" in
a)
all_files='true'
break
;;
b)
branch='true'
break
;;
c)
commits='true'
break
;;
h)
usage
@ -64,30 +71,38 @@ if [[ -n "${branch}" ]]; then
}' | \
fzf --no-multi --header='select a branch to checkout' \
--preview="/usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} log --oneline --graph --color=always --decorate=short {}")
[[ -z "${selected_branch}" ]] && exit 0
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_branch}"
exit 0
fi
if [[ -n "${all_files}" ]]; then
selected_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" ls-files --full-name --directory "${DOTBARE_TREE}" | \
fzf --multi --header='select a file to checkout version in HEAD' --preview "head -50 ${DOTBARE_TREE}/{}" | \
awk -v home="${DOTBARE_TREE}" '{print home "/" $0}')
[[ -z "${selected_branch}" ]] && exit 0
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_branch}"
exit 0
elif [[ -n "${commits}" ]]; then
selected_commits=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" log --oneline --color=always --decorate=short | \
fzf --no-multi --header='select which commit to reset' --preview "echo {} | awk '{print \$1}' | \
xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} show --color=always __" | \
awk '{print $1}')
[[ -z "${selected_commits}" ]] && exit 0
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_commits}"
exit 0
else
selected_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" diff --name-status | \
awk '{print "\033[31m" $1 " " $2}' | \
fzf --multi --header='select a file to checkout version in HEAD' \
--preview "echo {} | awk '{print \$2}' | \
xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} diff --color=always ${DOTBARE_TREE}/__" | \
awk -v home="${DOTBARE_TREE}" '{print home "/" $2}')
if [[ -n "${all_files}" ]]; then
selected_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" ls-files --full-name --directory "${DOTBARE_TREE}" | \
fzf --multi --header='select a file to checkout version in HEAD' --preview "head -50 ${DOTBARE_TREE}/{}" | \
awk -v home="${DOTBARE_TREE}" '{print home "/" $0}')
else
selected_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" diff --name-status | \
awk '{print "\033[31m" $1 " " $2}' | \
fzf --multi --header='select a file to checkout version in HEAD' \
--preview "echo {} | awk '{print \$2}' | \
xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} diff --color=always ${DOTBARE_TREE}/__" | \
awk -v home="${DOTBARE_TREE}" '{print home "/" $2}')
fi
[[ -z "${selected_files}" ]] && exit 0
while IFS= read -r line; do
echo "(dryrun) dotbare checkout -- ${line}"
done <<< "${selected_files}"
confirm=$(get_confirmation "Confirm?")
[[ "${confirm}" != 'y' ]] && exit 0
while IFS= read -r line; do
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout -- "${line}"
echo "${line} checkout success"
done <<< "${selected_files}"
fi
[[ -z "${selected_files}" ]] && exit 0
while IFS= read -r line; do
echo "(dryrun) dotbare checkout -- ${line}"
done <<< "${selected_files}"
confirm=$(get_confirmation "Confirm?")
[[ "${confirm}" != 'y' ]] && exit 0
while IFS= read -r line; do
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout -- "${line}"
echo "${line} checkout success"
done <<< "${selected_files}"

Loading…
Cancel
Save