|
|
|
@ -36,28 +36,32 @@ function usage() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
action_type="modified"
|
|
|
|
|
selected_files=()
|
|
|
|
|
|
|
|
|
|
while getopts ":habcy" opt
|
|
|
|
|
do
|
|
|
|
|
case "$opt" in
|
|
|
|
|
a)
|
|
|
|
|
action_type="allfiles"
|
|
|
|
|
while [[ "$#" -gt 0 ]]; do
|
|
|
|
|
case "$1" in
|
|
|
|
|
-s|--select)
|
|
|
|
|
action_type="select"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
b)
|
|
|
|
|
-b|--branch)
|
|
|
|
|
action_type="branch"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
c)
|
|
|
|
|
-c|--commit)
|
|
|
|
|
action_type="commit"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
y)
|
|
|
|
|
-y|--yes)
|
|
|
|
|
confirm="y"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
h)
|
|
|
|
|
-h|--help)
|
|
|
|
|
usage
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "Invalid option: ${OPTARG}" >&2
|
|
|
|
|
echo "Invalid option: $1" >&2
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
@ -69,33 +73,32 @@ if [[ "${action_type}" == "branch" ]]; then
|
|
|
|
|
selected_branch=$(get_branch 'Select a branch to checkout')
|
|
|
|
|
[[ -z "${selected_branch}" ]] && exit 0
|
|
|
|
|
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_branch}"
|
|
|
|
|
exit 0
|
|
|
|
|
elif [[ "${action_type}" == "commit" ]]; then
|
|
|
|
|
# checkout commit
|
|
|
|
|
selected_commit=$(get_commit 'Select a commit to checkout')
|
|
|
|
|
[[ -z "${selected_commit}" ]] && exit 0
|
|
|
|
|
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_commit}"
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
# checkout files (reset file changes back to HEAD)
|
|
|
|
|
if [[ "${action_type}" == "modified" ]]; then
|
|
|
|
|
selected_files=$(get_modified_file 'select a file to checkout version in HEAD' | tr '\n' ' ')
|
|
|
|
|
[[ -z "${selected_files}" ]] && exit 0
|
|
|
|
|
echo "(dryrun) dotbare checkout -- ${selected_files}"
|
|
|
|
|
[[ -z "${confirm}" ]] && confirm=$(get_confirmation "Confirm?")
|
|
|
|
|
[[ "${confirm}" != 'y' ]] && exit 1
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
|
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout -- ${selected_files}
|
|
|
|
|
elif [[ "${action_type}" == "allfiles" ]]; then
|
|
|
|
|
selected_files=$(get_git_file 'select a file to checkout' | tr '\n' ' ')
|
|
|
|
|
[[ -z "${selected_files}" ]] && exit 0
|
|
|
|
|
# continue select a commit and then checkout the file back to the selected commit
|
|
|
|
|
selected_commit=$(get_commit 'select the target commit' "${selected_files}")
|
|
|
|
|
[[ -z "${selected_commit}" ]] && exit 0
|
|
|
|
|
echo "(dryrun) dotbare checkout ${selected_commit} -- ${selected_files}"
|
|
|
|
|
[[ -z "${confirm}" ]] && confirm=$(get_confirmation "Confirm?")
|
|
|
|
|
[[ "${confirm}" != 'y' ]] && exit 0
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
|
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_commit}" ${selected_files}
|
|
|
|
|
fi
|
|
|
|
|
elif [[ "${action_type}" == "modified" ]]; then
|
|
|
|
|
# checkout modified file back to version in HEAD
|
|
|
|
|
while IFS= read -r line; do
|
|
|
|
|
selected_files+=("${line}")
|
|
|
|
|
done < <(get_modified_file 'select a file to checkout version in HEAD')
|
|
|
|
|
[[ "${#selected_files[@]}" -eq 0 ]] && exit 1
|
|
|
|
|
[[ -z "${confirm}" ]] && echo "(dryrun) dotbare checkout --" "${selected_files[@]}"
|
|
|
|
|
[[ -z "${confirm}" ]] && confirm=$(get_confirmation "Confirm?")
|
|
|
|
|
[[ "${confirm}" != 'y' ]] && exit 1
|
|
|
|
|
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout -- "${selected_files[@]}"
|
|
|
|
|
elif [[ "${action_type}" == "select" ]]; then
|
|
|
|
|
# checkout selected files to a selected commit
|
|
|
|
|
while IFS= read -r line; do
|
|
|
|
|
selected_files+=("${line}")
|
|
|
|
|
done < <(get_git_file 'select a file to checkout')
|
|
|
|
|
[[ "${#selected_files[@]}" -eq 0 ]] && exit 1
|
|
|
|
|
# continue select a commit and then checkout the file back to the selected commit
|
|
|
|
|
selected_commit=$(get_commit 'select the target commit' "${selected_files[@]}")
|
|
|
|
|
[[ -z "${selected_commit}" ]] && exit 1
|
|
|
|
|
[[ -z "${confirm}" ]] && echo "(dryrun) dotbare checkout ${selected_commit} --" "${selected_files[@]}"
|
|
|
|
|
[[ -z "${confirm}" ]] && confirm=$(get_confirmation "Confirm?")
|
|
|
|
|
[[ "${confirm}" != 'y' ]] && exit 0
|
|
|
|
|
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_commit}" "${selected_files[@]}"
|
|
|
|
|
fi
|
|
|
|
|