mirror of
https://github.com/tmux-plugins/tpm.git
synced 2026-09-10 07:26:18 -04:00
Add branches support to update_plugin.sh
This commit is contained in:
parent
99469c4a9b
commit
b7c27d9d13
|
|
@ -19,15 +19,52 @@ shift
|
|||
|
||||
pull_changes() {
|
||||
local plugin="$1"
|
||||
local branch="$2"
|
||||
local plugin_path="$(plugin_path_helper "$plugin")"
|
||||
cd "$plugin_path" &&
|
||||
GIT_TERMINAL_PROMPT=0 git pull &&
|
||||
GIT_TERMINAL_PROMPT=0 git submodule update --init --recursive
|
||||
(
|
||||
set -e
|
||||
|
||||
cd "$plugin_path"
|
||||
export GIT_TERMINAL_PROMPT=0
|
||||
|
||||
if [ -n "$branch" ]
|
||||
then
|
||||
# Since `clone()` in *install_plugins.sh* uses `--single-branch`, the
|
||||
# `remote.origin.fetch` is set to `+refs/tags/<BRANCH>:refs/tags/<BRANCH>`.
|
||||
# Thus, no other branch could be used, but only the one that was used
|
||||
# during the `clone()`.
|
||||
#
|
||||
# The following `git config` allows to use other branches that are
|
||||
# available on remote.
|
||||
git config remote.origin.fetch "+refs/heads/*:refs/tags/*"
|
||||
# Fetch recent branches/tags/commits.
|
||||
# `--tags` ensures that tags from the remote are fetched.
|
||||
# `--force` ensures that updated tags do not cause errors during fetch.
|
||||
git fetch --force --tags
|
||||
# `checkout` should be used after `fetch`.
|
||||
git checkout "$branch"
|
||||
# `merge` can only be used when HEAD points to a branch.
|
||||
if git show-ref --quiet --branches "$branch"
|
||||
then
|
||||
git merge --ff-only
|
||||
fi
|
||||
else
|
||||
# User might remove `#branch` suffix from config. In this case the
|
||||
# default origin branch should be set.
|
||||
local default_branch="$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')"
|
||||
git remote set-branches --add origin "$default_branch"
|
||||
git fetch --force --tags
|
||||
git checkout "$default_branch"
|
||||
git merge --ff-only
|
||||
fi
|
||||
git submodule update --init --recursive
|
||||
)
|
||||
}
|
||||
|
||||
update() {
|
||||
local plugin="$1" output
|
||||
output=$(pull_changes "$plugin" 2>&1)
|
||||
local branch="$2"
|
||||
output=$(pull_changes "$plugin" "$branch" 2>&1)
|
||||
if (( $? == 0 )); then
|
||||
echo_ok " \"$plugin\" update success"
|
||||
echo_ok "$(echo "$output" | sed -e 's/^/ | /')"
|
||||
|
|
@ -44,9 +81,10 @@ update_all() {
|
|||
for plugin in $plugins; do
|
||||
IFS='#' read -ra plugin <<< "$plugin"
|
||||
local plugin_name="$(plugin_name_helper "${plugin[0]}")"
|
||||
local branch="${plugin[1]}"
|
||||
# updating only installed plugins
|
||||
if plugin_already_installed "$plugin_name"; then
|
||||
update "$plugin_name" &
|
||||
update "$plugin_name" "$branch" &
|
||||
fi
|
||||
done
|
||||
wait
|
||||
|
|
@ -57,8 +95,9 @@ update_plugins() {
|
|||
for plugin in $plugins; do
|
||||
IFS='#' read -ra plugin <<< "$plugin"
|
||||
local plugin_name="$(plugin_name_helper "${plugin[0]}")"
|
||||
local branch="${plugin[1]}"
|
||||
if plugin_already_installed "$plugin_name"; then
|
||||
update "$plugin_name" &
|
||||
update "$plugin_name" "$branch" &
|
||||
else
|
||||
echo_err "$plugin_name not installed!" &
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in a new issue