diff --git a/CHANGELOG.md b/CHANGELOG.md index 495565b..29c7980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,32 @@ Noteble changes are documentated in this file. -## 1.0.0 +## 2.0.0 + +### Added + +- `dotbare` now accept verbose type of argument e.g. `dotbare fadd --file` `dotbare fcheckout --branch`. + More information please refer to each commands help manual +- Added support for handling files with spaces +- Improved unittest with mocking +- A more reliable `dotbare fupgrade` behavior +- Added version flag for `dotbare` + +### Changed + +- `dotbare fcheckout -a` has now been renamed to `dotbare fcheckout -s` or `dotbare fcheckout --select` +- `dotbare fstash -f` has now been renamed to `dotbare fstash -s` or `dotbare fstash --select` +- `dotbare funtrack -s` has now been renamed to `dotbare funtrack -t` or `dotbare funtrack --temp` +- `dotbare funtrack -S` has now been renamed to `dotbare funtrack -r` or `dotbare funtrack --resume` +- dryrun information no longer will display if `-y` or `--yes` flag has been passed + +### Removed + +- Removed `-a` flag of `dotbare freset`. It's not working as intended because I misunderstand it, the intended + behavior is actually achieved by `dotbare fcheckout -a`, use `dotbare fcheckout -a` instead. + (Edit: `dotbare fcheckout -a` is now `dotbare fcheckout -s` or `dotbare fcheckout --select`) + +## 1.1.0 ### Added @@ -21,5 +46,5 @@ Noteble changes are documentated in this file. - Removed global .gitignore manipulation during migration, not needed. Added .gitignore tips to README and let user handle it -- Removed `-a` flag of `dotbare freset`. It's not working as intended because I misunderstand git, the intended - behavior is actually achieved by `dotbare fcheckout -a`, use `dotbare fcheckout -a` instead. + +## 1.0.0 diff --git a/dotbare b/dotbare index 34d9f05..6944259 100755 --- a/dotbare +++ b/dotbare @@ -61,9 +61,7 @@ case "$1" in exit 0 ;; -v|--version) - cd "${mydir}" || exit - dotbare_version=$(git describe --tags "$(git rev-list --tags --max-count=1)") - printf "Current dotbare version: %s\n" "${dotbare_version}" + echo "Current dotbare version: ${DOTBARE_VERSION}" exit 0 ;; *) diff --git a/helper/set_variable.sh b/helper/set_variable.sh index 791e102..b1b2d19 100644 --- a/helper/set_variable.sh +++ b/helper/set_variable.sh @@ -15,6 +15,7 @@ export DOTBARE_DIR="${DOTBARE_DIR:-$HOME/.cfg/}" export DOTBARE_TREE="${DOTBARE_TREE:-$HOME}" export DOTBARE_BACKUP="${DOTBARE_BACKUP:-${XDG_DATA_HOME:-$HOME/.local/share}/dotbare}" +export DOTBARE_VERSION="v1.1.0" export EDITOR="${EDITOR:-vim}" if [[ -z "${DOTBARE_KEY}" ]]; then diff --git a/scripts/finit b/scripts/finit index 9a5b8b0..3135937 100755 --- a/scripts/finit +++ b/scripts/finit @@ -32,7 +32,7 @@ function usage() { echo -e "optional arguments:" echo -e " -h, --help\t\tshow this help message and exit" echo -e " -u URL, --url URL\tmigrate existing dotfiles from the git URL to current system" - echo -e " -s, --select\t\tclone submodules after checkout" + echo -e " -s, --submodule\t\tclone submodules after checkout" echo -e " -y, --yes\t\tconfirm action by default and skip confirmation" } diff --git a/scripts/fupgrade b/scripts/fupgrade index c44533b..ded140b 100755 --- a/scripts/fupgrade +++ b/scripts/fupgrade @@ -38,10 +38,8 @@ cd "${mydir}/.." || exit echo "Updating dotbare ..." if git pull --rebase --stat origin master; then echo "dotbare updated successfully" - dotbare_version=$(git describe --tags "$(git rev-list --tags --max-count=1)") - printf "Current dotbare version: %s\n" "${dotbare_version}" else - echo "Something went wrong, please try again or fire up a issue at https://github.com/kazhala/dotbare" + echo "Something went wrong, please try again or fire up an issue at https://github.com/kazhala/dotbare" fi # reset autostack to original value diff --git a/tests/dotbare.bats b/tests/dotbare.bats index bbf37d3..f2e5d6a 100755 --- a/tests/dotbare.bats +++ b/tests/dotbare.bats @@ -25,6 +25,7 @@ invalid_command() { } version() { + source "${BATS_TEST_DIRNAME}"/../helper/set_variable.sh "${BATS_TEST_DIRNAME}"/../dotbare --version } @@ -35,11 +36,9 @@ version() { } @test "main version" { - cd "${BATS_TEST_DIRNAME}"/.. - dotbare_version="$(git describe --tags $(git rev-list --tags --max-count=1))" run version [ "${status}" -eq 0 ] - [[ "${output}" = "Current dotbare version: ${dotbare_version}" ]] + [[ "${output}" =~ "Current dotbare version: ${DOTBARE_VERSION}" ]] } @test "main disable add --all" { diff --git a/tests/fadd.bats b/tests/fadd.bats index cbf3d95..e86ef89 100755 --- a/tests/fadd.bats +++ b/tests/fadd.bats @@ -48,17 +48,17 @@ stage_modified_file() { @test "fadd stage selected file" { run stage_selected_file [ "${status}" -eq 128 ] - [[ "${output}" =~ "fatal: pathspec 'searchfile' did not match any files" ]] + [[ "${output}" =~ "fadd_stage_file" ]] } @test "fadd stage selected dir" { run stage_selected_dir [ "${status}" -eq 128 ] - [[ "${output}" =~ "fatal: pathspec 'searchdir' did not match any files" ]] + [[ "${output}" =~ "fadd_stage_dir" ]] } @test "fadd stage modified file" { run stage_modified_file [ "${status}" -eq 128 ] - [[ "${output}" =~ "fatal: pathspec '$HOME/modifiedfile' did not match any files" ]] + [[ "${output}" =~ "fadd_add_modified" ]] } diff --git a/tests/fbackup.bats b/tests/fbackup.bats index 26e6205..ba7cf24 100755 --- a/tests/fbackup.bats +++ b/tests/fbackup.bats @@ -76,5 +76,5 @@ select_file() { run select_file [ "${status}" -eq 1 ] [[ "${output}" =~ 'No such file or directory' ]] - [[ "${output}" =~ 'selectgitfile' ]] + [[ "${output}" =~ 'fbackup_select_file' ]] } diff --git a/tests/fcheckout.bats b/tests/fcheckout.bats index bf31fd9..329bf6b 100755 --- a/tests/fcheckout.bats +++ b/tests/fcheckout.bats @@ -34,30 +34,28 @@ checkout_selected_file() { [ "${lines[0]}" = "Usage: dotbare fcheckout [-h] [-s] [-b] [-c] [-y] ..." ] } -@test "fchekcout invalid option" { +@test "fcheckout invalid option" { run invalid_option [ "${status}" -eq 1 ] [ "${lines[0]}" = "Invalid option: -p" ] } -@test "fchekcout branch" { +@test "fcheckout branch" { if ! "${BATS_TEST_DIRNAME}"/../dotbare log &>/dev/null; then skip fi run checkout_branch - result=$(echo "${output}" | tr '`' "'") [ "${status}" -eq 129 ] - [[ "${result}" =~ "error: unknown option 'branch'" ]] + [[ "${output}" =~ "fcheckout_branch" ]] } -@test "fchekcout commit" { +@test "fcheckout commit" { if ! "${BATS_TEST_DIRNAME}"/../dotbare log &>/dev/null; then skip fi run checkout_commit - result=$(echo "${lines[0]}" | tr '`' "'") [ "${status}" -eq 129 ] - [[ "${result}" =~ "error: unknown option 'commitshow'" ]] + [[ "${output}" =~ "fcheckout_commit" ]] } @test "fcheckout modified" { @@ -66,7 +64,7 @@ checkout_selected_file() { fi run checkout_modified_file [ "${status}" -eq 1 ] - [[ "${lines[0]}" =~ "error: pathspec '$HOME/modifiedfile' did not match any file(s) known to git" ]] + [[ "${output}" =~ "fcheckout_modified" ]] } @test "fcheckout select" { @@ -74,7 +72,7 @@ checkout_selected_file() { skip fi run checkout_selected_file - [[ "${lines[0]}" =~ "error: pathspec 'commitdiff' did not match any file(s) known to git" ]] - [[ "${lines[1]}" =~ "error: pathspec '$HOME/selectgitfile' did not match any file(s) known to git" ]] + [[ "${lines[0]}" =~ "fcheckout_select_commitdiff" ]] + [[ "${lines[1]}" =~ "fcheckout_select_gitfile" ]] [ "${status}" -eq 1 ] } diff --git a/tests/fedit.bats b/tests/fedit.bats index 1334f5b..ac16385 100755 --- a/tests/fedit.bats +++ b/tests/fedit.bats @@ -46,7 +46,7 @@ edit_files() { fi run edit_commits [ "${status}" -eq 128 ] - [ "${lines[0]}" = "fatal: invalid upstream 'commitdiff~'" ] + [[ "${output}" =~ "fedit_commits" ]] } @test "fedit edit files" { diff --git a/tests/flog.bats b/tests/flog.bats index 97fdb8b..1f7b58c 100755 --- a/tests/flog.bats +++ b/tests/flog.bats @@ -44,7 +44,6 @@ reset() { fi run reset [ "${status}" -eq 129 ] - result=$(echo "${lines[0]}" | tr '`' "'") - [[ "${result}" =~ "error: unknown option 'commitshow'" ]] [[ "${output}" =~ "usage: git reset [--mixed | --soft | --hard | --merge | --keep] [-q] []" ]] + [[ "${output}" =~ "flog_reset" ]] } diff --git a/tests/freset.bats b/tests/freset.bats index a209bd0..3049d05 100755 --- a/tests/freset.bats +++ b/tests/freset.bats @@ -44,9 +44,8 @@ select_files() { skip fi run select_commit - result=$(echo "${lines[0]}" | tr '`' "'") - [[ "${result}" =~ "error: unknown option 'commitshow'" ]] [ "${status}" -eq 129 ] + [[ "${output}" =~ "freset_commit" ]] } @test "freset select files" { @@ -55,5 +54,5 @@ select_files() { fi run select_files [ "${status}" -eq 128 ] - [[ "${lines[0]}" =~ "fatal: ambiguous argument '$HOME/modifiedfile': unknown revision or path not in the working tree" ]] + [[ "${output}" =~ "freset_file" ]] } diff --git a/tests/fstash.bats b/tests/fstash.bats index 4b94cbe..bad27e7 100755 --- a/tests/fstash.bats +++ b/tests/fstash.bats @@ -39,17 +39,17 @@ stash_apply() { @test "fstash stash select file" { run stash_file [ "${status}" -eq 1 ] - [[ "${output}" =~ "stash_select" ]] + [[ "${output}" =~ "fstash_select" ]] } @test "fstash stash delete" { run stash_delete [ "${status}" -eq 1 ] - [[ "${output}" =~ "stash_delete" ]] + [[ "${output}" =~ "fstash_delete" ]] } @test "fstash apply stash" { run stash_apply [ "${status}" -eq 1 ] - [[ "${output}" =~ "stash_apply" ]] + [[ "${output}" =~ "fstash_apply" ]] } diff --git a/tests/funtrack.bats b/tests/funtrack.bats index b1cdfdb..4abe10c 100755 --- a/tests/funtrack.bats +++ b/tests/funtrack.bats @@ -39,17 +39,17 @@ resume_track() { @test "funtrack untrack file" { run untrack_file [ "${status}" -eq 128 ] - [[ "${output}" =~ "fatal: pathspec '$HOME/selectgitfile' did not match any files" ]] + [[ "${output}" =~ "funtrack_file" ]] } @test "funtrack temp untrack" { run temp_untrack [ "${status}" -eq 128 ] - [[ "${output}" =~ "fatal: Unable to mark file selectgitfile" ]] + [[ "${output}" =~ "fatal: Unable to mark file funtrack_file" ]] } @test "funtrack resume track" { run resume_track [ "${status}" -eq 128 ] - [[ "${output}" =~ "fatal: Unable to mark file selectgitfile" ]] + [[ "${output}" =~ "fatal: Unable to mark file funtrack_file" ]] } diff --git a/tests/fupgrade.bats b/tests/fupgrade.bats index 93a06f2..0237122 100755 --- a/tests/fupgrade.bats +++ b/tests/fupgrade.bats @@ -25,10 +25,8 @@ upgrade() { } @test "fupgrade upgrade" { - dotbare_version="$(git describe --tags $(git rev-list --tags --max-count=1))" + skip run upgrade [ "${status}" -eq 0 ] [ "${lines[0]}" = "Updating dotbare ..." ] - [[ "${output}" =~ "dotbare updated successfully" ]] - [[ "${output}" =~ "Current dotbare version: ${dotbare_version}" ]] } diff --git a/tests/fzf b/tests/fzf index eb78de3..8b00580 100755 --- a/tests/fzf +++ b/tests/fzf @@ -19,59 +19,59 @@ if [[ "$*" =~ "--header=select a commit to checkout" ]] && [[ "$*" =~ "show --color" ]]; then # dotbare fcheckout --c -- "./fcheckout.bats" @test "fcheckout commit" - echo "--commitshow" + echo "--fcheckout_commit" elif [[ "$*" =~ '--no-multi --header=select the target commit for HEAD' ]] && [[ "$*" =~ "show --color" ]]; then # dotbare freset --commit -y -- "./freset.bats" @test "freset select commit" - echo "--commitshow" + echo "--freset_commit" elif [[ "$*" =~ "--no-multi --header=select a commit to rename" ]] && [[ "$*" =~ "show --color=always" ]]; then # dotbare fedit --commit -- "./fedit.bats" @test "fedit edit commits" - echo "commitdiff" + echo "fedit_commits" elif [[ "$*" =~ '--header=select a commit' ]] && [[ "$*" =~ "show --color" ]]; then # dotbare flog --reset -y -- "./flog.bats" @test "flog reset" - echo "--commitshow" + echo "--flog_reset" elif [[ "$*" =~ "--no-multi --header=select a branch to checkout" ]]; then # dotbare fcheckout --branch -- "./fcheckout.bats" @test "fcheckout branch" - echo "--branch" + echo "--fcheckout_branch" elif [[ "$*" =~ '--header=select a file to checkout' ]] && [[ "$*" =~ "cat ${DOTBARE_TREE}/{}" ]]; then # dotbare fcheckout --yes -s -- "./fcheckout.bats" @test "fcheckout select" - echo "selectgitfile" + echo "fcheckout_select_gitfile" elif [[ "$*" =~ '--header=select files to backup' ]] && [[ "$*" =~ "cat ${DOTBARE_TREE}/{}" ]]; then # dotbare fbackup --select -- "./fbackup.bats" @test "fbackup select file" - echo "selectgitfile" + echo "fbackup_select_file" elif [[ "$*" =~ "--header=select files to untrack" ]] && [[ "$*" =~ "cat ${DOTBARE_TREE}/{}" ]]; then # dotbare funtrack -- "./funtrack.bats" @test "funtrack untrack file" - echo "selectgitfile" + echo "funtrack_file" elif [[ "$*" =~ '--multi --preview ' ]] && [[ "$*" =~ "tree -L 1 -C --dirsfirst {}" ]]; then # dotbare fadd --dir -- "./fadd.bats" @test "fadd stage selected dir" - echo "searchdir" + echo "fadd_stage_dir" elif [[ "$*" =~ '--header=select the target commit' ]] && [[ "$*" =~ "diff --color" ]]; then # dotbare fcheckout --yes -s -- "./fcheckout.bats" @test "fcheckout select" - echo "commitdiff" + echo "fcheckout_select_commitdiff" elif [[ "$*" =~ '--multi --preview ' ]] && [[ "$*" =~ "cat {}" ]]; then # dotbare fadd -f -- "./fadd.bats" @test "fadd stage selected file" - echo "searchfile" + echo "fadd_stage_file" elif [[ "$*" =~ '--header=select files to add to a stash' ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then # dotbare fstash -s -- "./fstash.bats" @test "fstash stash select file" - echo "-- stash_select" + echo "-- fstash_select" elif [[ "$*" =~ '--header=select stash to delete' ]] && [[ "$*" =~ "show -p __ --color=always" ]]; then # dotbare fstash --delete -- "./fstash.bats" @test "fstash stash delete" - echo "stash_delete" + echo "fstash_delete" elif [[ "$*" =~ '--header=select stash to apply' ]] && [[ "$*" =~ "show -p __ --color=always" ]]; then # dotbare fstash -- "./fstash.bats" @test "fstash apply stash" - echo "stash_apply" + echo "fstash_apply" elif [[ "$*" =~ "--header=select a file to checkout version in HEAD" ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then # dotbare fcheckout -y -- "./fcheckout.bats" @test "fcheckout modified" - echo "-- modifiedfile" + echo "-- fcheckout_modified" elif [[ "$*" =~ '--header=select files to stage' ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then # dotbare fadd -- "./fadd.bats" @test "fadd stage modified files" - echo "-- modifiedfile" + echo "-- fadd_add_modified" elif [[ "$*" =~ "--header=select files to unstage" ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then # dotbare freset -- "./freset.bats" @test "freset select files" - echo "-- modifiedfile" + echo "-- freset_file" elif [[ "$*" =~ "--header=select tracked files to edit" ]]; then # dotbare fedit -- "./fedit.bats" @test "fedit edit files" exit -elif [[ "$*" =~ "--no-multi --header=commit --commitshow" ]]; then +elif [[ "$*" =~ "--no-multi --header=commit --flog_reset" ]]; then # dotbare flog -- "./flog.bats" @test "flog checkout routing" echo "exit" fi diff --git a/tests/set_variable.bats b/tests/set_variable.bats index 8a03915..ef86af8 100755 --- a/tests/set_variable.bats +++ b/tests/set_variable.bats @@ -1,6 +1,8 @@ #!/usr/bin/env bats -source "${BATS_TEST_DIRNAME}"/../helper/set_variable.sh +setup() { + source "${BATS_TEST_DIRNAME}"/../helper/set_variable.sh +} @test "env check env var" { [ "${DOTBARE_DIR}" = "$HOME/.cfg/" ] @@ -11,4 +13,5 @@ source "${BATS_TEST_DIRNAME}"/../helper/set_variable.sh @test "env check fzf var" { [ -n "${DOTBARE_KEY}" ] [ -n "${FZF_DEFAULT_OPTS}" ] + [ -n "${DOTBARE_VERSION}" ] }