Skip to content

Commit

Permalink
Merge branch 'fix-apt_add' into 'main'
Browse files Browse the repository at this point in the history
Fix apt_add fails on apt-key not found even if it is present

See merge request xebis/shellib!25
  • Loading branch information
bruzina committed Jan 8, 2022
2 parents bc570c2 + a1fcfa2 commit 1405fb2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function apt_add() {
return "$status_err"
fi

if ! apt-add-repository -h &>/dev/null || ! apt-key -h &>/dev/null; then
if ! apt-add-repository -h &>/dev/null || [ "$(apt-key -h)" == '' ]; then
err 'apt-add-repository or apt-key not found'
return "$status_err"
fi
Expand Down
26 changes: 23 additions & 3 deletions tests/packages.sh.bats
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ setup() {

function apt-key() {
echo 'Help'
return 1
}
export -f apt-key

Expand All @@ -253,7 +254,10 @@ setup() {

function apt-key() {
case "$1" in
-h) echo 'Help' ;;
-h)
echo 'Help'
return 1
;;
add)
echo "No key at '$2'"
return 1
Expand Down Expand Up @@ -293,7 +297,15 @@ setup() {
export -f apt-add-repository

function apt-key() {
echo
case "$1" in
-h)
echo 'Help'
return 1
;;
add)
echo
;;
esac
}
export -f apt-key

Expand Down Expand Up @@ -322,7 +334,15 @@ setup() {
export -f apt-add-repository

function apt-key() {
echo
case "$1" in
-h)
echo 'Help'
return 1
;;
add)
echo
;;
esac
}
export -f apt-key

Expand Down

0 comments on commit 1405fb2

Please sign in to comment.