test(fcheckout): update test for fcheckout

pull/17/head
Kevin Zhuang 4 years ago
parent 245b9a66a2
commit 4c2a5a9b28

@ -21,7 +21,7 @@ function get_commit() {
if [[ "${#files[@]}" -eq 0 ]]; then
git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" \
log --color=always --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' \
| fzf --no-multi --header="${header}" \
| fzf --header="${header}" --no-multi \
--preview "echo {} \
| awk '{print \$1}' \
| xargs -I __ git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} \
@ -31,7 +31,7 @@ function get_commit() {
else
git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" \
log --oneline --color=always --decorate=short \
| fzf --no-multi --header="${header}" --preview "echo {} \
| fzf --header="${header}" --no-multi --preview "echo {} \
| awk '{print \$1}' \
| xargs -I __ git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} \
diff --color=always __ ${files[*]} \

@ -79,12 +79,12 @@ if [[ "${action_type}" == "branch" ]]; then
# checkout branch
selected_branch=$(get_branch 'select a branch to checkout')
[[ -z "${selected_branch}" ]] && exit 1
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_branch}"
git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_branch}"
elif [[ "${action_type}" == "commit" ]]; then
# checkout commit
selected_commit=$(get_commit 'select a commit to checkout')
[[ -z "${selected_commit}" ]] && exit 1
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_commit}"
git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_commit}"
elif [[ "${action_type}" == "modified" ]]; then
# checkout modified file back to version in HEAD
while IFS= read -r line; do
@ -94,7 +94,7 @@ elif [[ "${action_type}" == "modified" ]]; then
[[ -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[@]}"
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
@ -107,5 +107,5 @@ elif [[ "${action_type}" == "select" ]]; then
[[ -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[@]}"
git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_commit}" "${selected_files[@]}"
fi

@ -41,38 +41,26 @@ checkout_selected_file() {
}
@test "fcheckout branch" {
if ! "${BATS_TEST_DIRNAME}"/../dotbare log &>/dev/null; then
skip
fi
run checkout_branch
[ "${status}" -eq 129 ]
[[ "${output}" =~ "fcheckout_branch" ]]
[[ "${output}" =~ "checkout" ]]
[[ "${output}" =~ "--no-multi --header=select a branch to checkout" ]]
}
@test "fcheckout commit" {
if ! "${BATS_TEST_DIRNAME}"/../dotbare log &>/dev/null; then
skip
fi
run checkout_commit
[ "${status}" -eq 129 ]
[[ "${output}" =~ "fcheckout_commit" ]]
[[ "${output}" =~ "checkout --header=select" ]]
}
@test "fcheckout modified" {
if ! "${BATS_TEST_DIRNAME}"/../dotbare log &>/dev/null; then
skip
fi
run checkout_modified_file
[ "${status}" -eq 1 ]
[[ "${output}" =~ "fcheckout_modified" ]]
[[ "${output}" =~ "checkout" ]]
[[ "${output}" =~ "file to checkout version in HEAD" ]]
[[ "${output}" =~ "diff HEAD --color=always" ]]
}
@test "fcheckout select" {
if ! "${BATS_TEST_DIRNAME}"/../dotbare log &>/dev/null; then
skip
fi
run checkout_selected_file
[[ "${lines[0]}" =~ "fcheckout_select_commitdiff" ]]
[[ "${lines[1]}" =~ "fcheckout_select_gitfile" ]]
[ "${status}" -eq 1 ]
[[ "${output}" =~ "checkout" ]]
[[ "${output}" =~ "--header=select a file to checkout" ]]
[[ "${output}" =~ "preview.sh" ]]
}

Loading…
Cancel
Save