2
0
mirror of https://github.com/kazhala/dotbare synced 2024-11-04 06:00:45 +00:00

test(fcheckout): update test for fcheckout

This commit is contained in:
Kevin Zhuang 2020-07-07 12:01:59 +10:00
parent 245b9a66a2
commit 4c2a5a9b28
3 changed files with 15 additions and 27 deletions

View File

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

View File

@ -79,12 +79,12 @@ if [[ "${action_type}" == "branch" ]]; then
# checkout branch # checkout branch
selected_branch=$(get_branch 'select a branch to checkout') selected_branch=$(get_branch 'select a branch to checkout')
[[ -z "${selected_branch}" ]] && exit 1 [[ -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 elif [[ "${action_type}" == "commit" ]]; then
# checkout commit # checkout commit
selected_commit=$(get_commit 'select a commit to checkout') selected_commit=$(get_commit 'select a commit to checkout')
[[ -z "${selected_commit}" ]] && exit 1 [[ -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 elif [[ "${action_type}" == "modified" ]]; then
# checkout modified file back to version in HEAD # checkout modified file back to version in HEAD
while IFS= read -r line; do 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}" ]] && echo "(dryrun) dotbare checkout --" "${selected_files[@]}"
[[ -z "${confirm}" ]] && confirm=$(get_confirmation "Confirm?") [[ -z "${confirm}" ]] && confirm=$(get_confirmation "Confirm?")
[[ "${confirm}" != 'y' ]] && exit 1 [[ "${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 elif [[ "${action_type}" == "select" ]]; then
# checkout selected files to a selected commit # checkout selected files to a selected commit
while IFS= read -r line; do 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}" ]] && echo "(dryrun) dotbare checkout ${selected_commit} --" "${selected_files[@]}"
[[ -z "${confirm}" ]] && confirm=$(get_confirmation "Confirm?") [[ -z "${confirm}" ]] && confirm=$(get_confirmation "Confirm?")
[[ "${confirm}" != 'y' ]] && exit 0 [[ "${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 fi

View File

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