Just use `diff` in `backups compare`.

This commit is contained in:
William Melody 2020-04-08 21:25:01 -07:00
parent 7fc3b994b4
commit fb67d7b510
2 changed files with 5 additions and 16 deletions

19
hosts
View File

@ -749,14 +749,15 @@ Subcommands:
backups List available backups.
backups create Create a new backup of the hosts file.
backups compare Compare a backup file with the current hosts file.
The diff tool configured for git will be used if
one is set.
backups delete Delete the specified backup.
backups restore Replace the contents of the hosts file with a
specified backup. The hosts file is automatically
backed up before being overwritten unless the
'--skip-backup' flag is specified.
backups show Show the contents of the specified backup file.
Description:
Manage backups.
HEREDOC
backups() {
local _subcommand="${1:-}"
@ -804,19 +805,7 @@ backups() {
exit 1
fi
local _difftool="diff"
if ! ((_use_diff))
then
if command -v git &>/dev/null
then
local _git_merge_tool
_git_merge_tool="$(git config --get merge.tool)"
[[ -n "${_git_merge_tool}" ]] && _difftool="${_git_merge_tool}"
fi
fi
"${_difftool}" "${HOSTS_PATH}" "${_hosts_dirname}/${_filename}"
diff -u "${HOSTS_PATH}" "${_hosts_dirname}/${_filename}"
;;
delete)
if [[ -z "${1:-}" ]]

View File

@ -87,7 +87,7 @@ No backups found. Create a new backup:
printf "\${output}: '%s'\\n" "${output}"
printf "\${lines[1]}: '%s'\\n" "${lines[1]}"
[[ ${status} -eq 1 ]]
[[ "${lines[1]}" =~ \<\ 0.0.0.0[[:space:]]+example.com ]]
[[ "${lines[2]}" == '@@ -8,4 +8,3 @@' ]]
}
@test "\`backups compare\` with missing backup exits with status 1" {