refactor fstash and fix pipeline

pull/3/head
kevin zhuang 4 years ago
parent 5ae27efc12
commit 1094c697bd

@ -5,7 +5,7 @@
# @params
# Globals
# ${mydir}: current dir of the script, source purpose
# ${stash_file}: select modified files and stash
# ${stash_command}: stash command, pop, apply or file/delete to stash file or delete stash
# ${selected_file}: selected files to stash
# ${selected_stash}: selected stash to apply
# Arguments
@ -34,23 +34,21 @@ function usage() {
echo -e " -p\tuse pop instead of apply when retrieving stash"
}
stash_file=""
delete_stash=""
stash_command="apply"
while getopts ":hdfp" opt; do
while getopts ":hdfpy" opt; do
case "$opt" in
p)
stash_command="pop"
break
;;
f)
stash_file="true"
break
stash_command="file"
;;
d)
delete_stash="true"
break
stash_command="delete"
;;
y)
confirm='y'
;;
h)
usage
@ -64,18 +62,18 @@ while getopts ":hdfp" opt; do
esac
done
if [[ -n "${stash_file}" ]]; then
if [[ "${stash_command}" == "file" ]]; then
selected_file=$(get_modified_file "select files to add to a stash")
[[ -z "${selected_file}" ]] && exit 1
# shellcheck disable=SC2086
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" stash -- ${selected_file}
elif [[ -n "${delete_stash}" ]]; then
elif [[ "${stash_command}" == "delete" ]]; then
selected_stash=$(get_stash "select stash to delete")
[[ -z "${selected_stash}" ]] && exit 1
while IFS= read -r line; do
echo "(dryrun) Drop ${line}"
done <<< "${selected_stash}"
confirm=$(get_confirmation)
[[ -z "${confirm}" ]] && confirm=$(get_confirmation)
[[ "${confirm}" != 'y' ]] && exit 1
while IFS= read -r line; do
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" stash drop "${line}"

@ -6,7 +6,7 @@ setup() {
}
teardown() {
rm -r "$DOTBARE_BACKUP"
[ -d "${DOTBARE_BACKUP}" ] && rm -r "$DOTBARE_BACKUP"
unset DOTBARE_BACKUP
}
@ -28,7 +28,7 @@ individual_backup() {
}
check_empty() {
git log
bash "${BATS_TEST_DIRNAME}"/../dotbare log
}
@test "fbackup help" {

Loading…
Cancel
Save