Skip to content
Snippets Groups Projects
Commit 22a393b7 authored by Robin Candau's avatar Robin Candau
Browse files

feat(version upgrade): Add diff & confirmation for pkgctl version upgrade

`pkgctl version upgrade` now shows a `git diff` of the changes made to the PKGBUILD file and asks for user's confirmation.
If changes are not confirmed, the changes are reverted via `git checkout`.
Users can pass the `--noconfirm` flag to avoid being asked for a confirmation.

Closes archlinux/devtools#239
parent 27eebe38
No related branches found
No related tags found
No related merge requests found
Pipeline #102644 passed
......@@ -388,6 +388,7 @@ _pkgctl_version_setup_args__url_opts() { :; }
_pkgctl_version_upgrade_args=(
--no-update-checksums
--noconfirm
-v --verbose
-h --help
)
......
......@@ -323,6 +323,7 @@ _pkgctl_version_setup_args=(
_pkgctl_version_upgrade_args=(
'--no-update-checksums[Disable computation and update of the checksums]'
'--noconfirm[Do not ask to confirm changes made to the PKGBUILD file]'
'(-v --verbose)'{-v,--verbose}'[Display results including up-to-date versions]'
'(-h --help)'{-h,--help}'[Display usage]'
'*:git_dir:_files -/'
......
......@@ -38,6 +38,9 @@ Options
*--no-update-checksums*::
Disable computation and update of the checksums
*--noconfirm*::
Do not ask to confirm changes made to the PKGBUILD file
*-v, --verbose*::
Display results including up-to-date versions
......
......@@ -37,6 +37,7 @@ pkgctl_version_upgrade_usage() {
OPTIONS
--no-update-checksums Disable computation and update of the checksums
--noconfirm Do not ask to confirm changes made to the PKGBUILD file
-v, --verbose Display results including up-to-date versions
-h, --help Show this help text
......@@ -52,6 +53,7 @@ pkgctl_version_upgrade() {
local exit_code=0
local current_item=0
local update_checksums=1
local noconfirm=0
while (( $# )); do
case $1 in
......@@ -63,6 +65,10 @@ pkgctl_version_upgrade() {
update_checksums=0
shift
;;
--noconfirm)
noconfirm=1
shift
;;
-v|--verbose)
verbose=1
shift
......@@ -225,6 +231,22 @@ pkgctl_version_upgrade() {
"${#failure[@]}"
fi
# ask confirmation about changes made to PKGBUILD
if (( noconfirm == 0 )); then
echo
git diff PKGBUILD
read -rep $'\nConfirm changes (not confirming will revert all the above changes)? [Y/n] ' answer
case $answer in
"Y"|"y"|"")
true
;;
*)
printf "\nReverting changes...\n"
git checkout PKGBUILD
;;
esac
fi
# return status based on results
return "${exit_code}"
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment