1717# from now on ignore first script argument
1818shift
1919
20+ is_branch () {
21+ git show-ref --quiet --branches " $1 " 2> /dev/null
22+ case " $? " in
23+ 129) git show-ref --quiet --heads " $1 " 2> /dev/null ;;
24+ * ) return " $? " ;;
25+ esac
26+ }
27+
2028pull_changes () {
2129 local plugin=" $1 "
30+ local branch=" ${2:- " $( git remote show origin | sed -n ' /HEAD branch/s/.*: //p' ) " } "
2231 local plugin_path=" $( plugin_path_helper " $plugin " ) "
23- cd " $plugin_path " &&
24- GIT_TERMINAL_PROMPT=0 git pull &&
25- GIT_TERMINAL_PROMPT=0 git submodule update --init --recursive
32+ (
33+ set -e
34+
35+ cd " $plugin_path "
36+ export GIT_TERMINAL_PROMPT=0
37+
38+ # Since `clone()` in *install_plugins.sh* uses `--single-branch`, the
39+ # `remote.origin.fetch` is set to `+refs/tags/<BRANCH>:refs/tags/<BRANCH>`.
40+ # Thus, no other branch could be used, but only the one that was used
41+ # during the `clone()`.
42+ #
43+ # The following `git config` allows to use other branches that are
44+ # available on remote.
45+ git config --replace-all remote.origin.fetch ' +refs/heads/*:refs/remotes/origin/*'
46+ # Fetch recent branches/tags/commits.
47+ # `--tags` ensures that tags from the remote are fetched.
48+ # `--force` ensures that updated tags do not cause errors during fetch.
49+ git fetch --force --tags
50+ # `checkout` should be used after `fetch`.
51+ git checkout " $branch "
52+ # `merge` can only be used when HEAD points to a branch.
53+ if is_branch " $branch "
54+ then
55+ git merge --ff-only
56+ fi
57+
58+ git submodule update --init --recursive
59+ )
2660}
2761
2862update () {
2963 local plugin=" $1 " output
30- output=$( pull_changes " $plugin " 2>&1 )
64+ local branch=" $2 "
65+ output=$( pull_changes " $plugin " " $branch " 2>&1 )
3166 if (( $? == 0 )) ; then
3267 echo_ok " \" $plugin \" update success"
3368 echo_ok " $( echo " $output " | sed -e ' s/^/ | /' ) "
@@ -44,9 +79,10 @@ update_all() {
4479 for plugin in $plugins ; do
4580 IFS=' #' read -ra plugin <<< " $plugin"
4681 local plugin_name=" $( plugin_name_helper " ${plugin[0]} " ) "
82+ local branch=" ${plugin[1]} "
4783 # updating only installed plugins
4884 if plugin_already_installed " $plugin_name " ; then
49- update " $plugin_name " &
85+ update " $plugin_name " " $branch " &
5086 fi
5187 done
5288 wait
@@ -57,8 +93,9 @@ update_plugins() {
5793 for plugin in $plugins ; do
5894 IFS=' #' read -ra plugin <<< " $plugin"
5995 local plugin_name=" $( plugin_name_helper " ${plugin[0]} " ) "
96+ local branch=" ${plugin[1]} "
6097 if plugin_already_installed " $plugin_name " ; then
61- update " $plugin_name " &
98+ update " $plugin_name " " $branch " &
6299 else
63100 echo_err " $plugin_name not installed!" &
64101 fi
0 commit comments