17
17
# from now on ignore first script argument
18
18
shift
19
19
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
+
20
28
pull_changes () {
21
29
local plugin=" $1 "
30
+ local branch=" ${2:- " $( git remote show origin | sed -n ' /HEAD branch/s/.*: //p' ) " } "
22
31
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
+ )
26
60
}
27
61
28
62
update () {
29
63
local plugin=" $1 " output
30
- output=$( pull_changes " $plugin " 2>&1 )
64
+ local branch=" $2 "
65
+ output=$( pull_changes " $plugin " " $branch " 2>&1 )
31
66
if (( $? == 0 )) ; then
32
67
echo_ok " \" $plugin \" update success"
33
68
echo_ok " $( echo " $output " | sed -e ' s/^/ | /' ) "
@@ -44,9 +79,10 @@ update_all() {
44
79
for plugin in $plugins ; do
45
80
IFS=' #' read -ra plugin <<< " $plugin"
46
81
local plugin_name=" $( plugin_name_helper " ${plugin[0]} " ) "
82
+ local branch=" ${plugin[1]} "
47
83
# updating only installed plugins
48
84
if plugin_already_installed " $plugin_name " ; then
49
- update " $plugin_name " &
85
+ update " $plugin_name " " $branch " &
50
86
fi
51
87
done
52
88
wait
@@ -57,8 +93,9 @@ update_plugins() {
57
93
for plugin in $plugins ; do
58
94
IFS=' #' read -ra plugin <<< " $plugin"
59
95
local plugin_name=" $( plugin_name_helper " ${plugin[0]} " ) "
96
+ local branch=" ${plugin[1]} "
60
97
if plugin_already_installed " $plugin_name " ; then
61
- update " $plugin_name " &
98
+ update " $plugin_name " " $branch " &
62
99
else
63
100
echo_err " $plugin_name not installed!" &
64
101
fi
0 commit comments