mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-21 21:53:43 +00:00
Move functions to piholeCheckout.sh
Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
parent
2e0746707d
commit
d9e4e1111f
2 changed files with 86 additions and 87 deletions
|
@ -38,6 +38,92 @@ warning1() {
|
|||
esac
|
||||
}
|
||||
|
||||
fully_fetch_repo() {
|
||||
# Add upstream branches/tags to shallow clone
|
||||
local directory="${1}"
|
||||
|
||||
cd "${directory}" || return 1
|
||||
if is_repo "${directory}"; then
|
||||
git remote set-branches origin '*' || return 1
|
||||
git fetch --tags --quiet || return 1
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
get_available_refs() {
|
||||
# Return available branches and tags
|
||||
local directory
|
||||
directory="${1}"
|
||||
local output
|
||||
|
||||
cd "${directory}" || return 1
|
||||
# Get reachable remote branches and tags, but store STDERR as STDOUT variable
|
||||
output=$( { git ls-remote --heads --tags --quiet | cut -d'/' -f3- -; } 2>&1 )
|
||||
# echo status for calling function to capture
|
||||
echo "$output"
|
||||
return
|
||||
}
|
||||
|
||||
fetch_checkout_pull_branch() {
|
||||
# Check out specified branch
|
||||
local directory
|
||||
directory="${1}"
|
||||
local branch
|
||||
branch="${2}"
|
||||
|
||||
# Set the reference for the requested branch, fetch, check it put and pull it
|
||||
cd "${directory}" || return 1
|
||||
git remote set-branches origin "${branch}" || return 1
|
||||
git stash --all --quiet &> /dev/null || true
|
||||
git clean --quiet --force -d || true
|
||||
git fetch --quiet || return 1
|
||||
checkout_pull_ref "${directory}" "${branch}" || return 1
|
||||
}
|
||||
|
||||
checkout_pull_ref() {
|
||||
# Check out specified branch/tag
|
||||
local directory
|
||||
directory="${1}"
|
||||
local ref
|
||||
ref="${2}"
|
||||
local oldref
|
||||
local ref_is_tag
|
||||
|
||||
cd "${directory}" || return 1
|
||||
|
||||
# Get current branch name.
|
||||
oldref="$(git symbolic-ref --quiet HEAD)"
|
||||
|
||||
str="Switching to branch/tag: '${ref}' from '${oldref}'"
|
||||
printf " %b %s" "${INFO}" "$str"
|
||||
|
||||
# check if the ref is a branch or a tag on the remote repo
|
||||
if git show-ref -q --verify "refs/remotes/origin/$ref" 2>/dev/null; then
|
||||
ref_is_tag=false
|
||||
elif git show-ref -q --verify "refs/tags/$ref" 2>/dev/null; then
|
||||
ref_is_tag=true
|
||||
fi
|
||||
|
||||
if [ "$ref_is_tag" = true ]; then
|
||||
# in case we want to checkout a tag we need explicitly create a new branch/reset the existing one
|
||||
git checkout -B "${ref}" "refs/tags/${ref}" --quiet || return 1
|
||||
printf "%b %b %s\\n" "${OVER}" "${TICK}" "$str"
|
||||
else
|
||||
# checkout a branch, this also sets tracking branch
|
||||
git checkout "${ref}" --quiet || return 1
|
||||
printf "%b %b %s\\n" "${OVER}" "${TICK}" "$str"
|
||||
git_pull=$(git pull --no-rebase || return 1)
|
||||
printf " %b %s\\n" "${INFO}" "${git_pull}"
|
||||
fi
|
||||
|
||||
# Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git)
|
||||
chmod -R a+rX "${directory}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
checkout() {
|
||||
local corerefs
|
||||
local webrefs
|
||||
|
|
|
@ -2114,93 +2114,6 @@ check_download_exists() {
|
|||
fi
|
||||
}
|
||||
|
||||
fully_fetch_repo() {
|
||||
# Add upstream branches/tags to shallow clone
|
||||
local directory="${1}"
|
||||
|
||||
cd "${directory}" || return 1
|
||||
if is_repo "${directory}"; then
|
||||
git remote set-branches origin '*' || return 1
|
||||
git fetch --tags --quiet || return 1
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
get_available_refs() {
|
||||
# Return available branches and tags
|
||||
local directory
|
||||
directory="${1}"
|
||||
local output
|
||||
|
||||
cd "${directory}" || return 1
|
||||
# Get reachable remote branches and tags, but store STDERR as STDOUT variable
|
||||
output=$( { git ls-remote --heads --tags --quiet | cut -d'/' -f3- -; } 2>&1 )
|
||||
# echo status for calling function to capture
|
||||
echo "$output"
|
||||
return
|
||||
}
|
||||
|
||||
fetch_checkout_pull_branch() {
|
||||
# Check out specified branch
|
||||
local directory
|
||||
directory="${1}"
|
||||
local branch
|
||||
branch="${2}"
|
||||
|
||||
# Set the reference for the requested branch, fetch, check it put and pull it
|
||||
cd "${directory}" || return 1
|
||||
git remote set-branches origin "${branch}" || return 1
|
||||
git stash --all --quiet &> /dev/null || true
|
||||
git clean --quiet --force -d || true
|
||||
git fetch --quiet || return 1
|
||||
checkout_pull_ref "${directory}" "${branch}" || return 1
|
||||
}
|
||||
|
||||
checkout_pull_ref() {
|
||||
# Check out specified branch/tag
|
||||
local directory
|
||||
directory="${1}"
|
||||
local ref
|
||||
ref="${2}"
|
||||
local oldref
|
||||
local ref_is_tag
|
||||
|
||||
cd "${directory}" || return 1
|
||||
|
||||
# Get current branch name.
|
||||
oldref="$(git symbolic-ref --quiet HEAD)"
|
||||
|
||||
str="Switching to branch/tag: '${ref}' from '${oldref}'"
|
||||
printf " %b %s" "${INFO}" "$str"
|
||||
|
||||
# check if the ref is a branch or a tag on the remote repo
|
||||
if git show-ref -q --verify "refs/remotes/origin/$ref" 2>/dev/null; then
|
||||
ref_is_tag=false
|
||||
elif git show-ref -q --verify "refs/tags/$ref" 2>/dev/null; then
|
||||
ref_is_tag=true
|
||||
fi
|
||||
|
||||
if [ "$ref_is_tag" = true ]; then
|
||||
# in case we want to checkout a tag we need explicitly create a new branch/reset the existing one
|
||||
git checkout -B "${ref}" "refs/tags/${ref}" --quiet || return 1
|
||||
printf "%b %b %s\\n" "${OVER}" "${TICK}" "$str"
|
||||
else
|
||||
# checkout a branch, this also sets tracking branch
|
||||
git checkout "${ref}" --quiet || return 1
|
||||
printf "%b %b %s\\n" "${OVER}" "${TICK}" "$str"
|
||||
git_pull=$(git pull --no-rebase || return 1)
|
||||
printf " %b %s\\n" "${INFO}" "${git_pull}"
|
||||
fi
|
||||
|
||||
# Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git)
|
||||
chmod -R a+rX "${directory}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
clone_or_update_repos() {
|
||||
# If the user wants to reconfigure,
|
||||
if [[ "${reconfigure}" == true ]]; then
|
||||
|
|
Loading…
Reference in a new issue