@@ -30,6 +30,7 @@ M.log = {
30
30
elseif opts .check then
31
31
local info = assert (Git .info (self .plugin .dir ))
32
32
local target = assert (Git .get_target (self .plugin ))
33
+ assert (target .commit , self .plugin .name .. " " .. target .branch )
33
34
table.insert (args , info .commit .. " .." .. target .commit )
34
35
else
35
36
vim .list_extend (args , opts .args or Config .options .git .log )
@@ -76,22 +77,23 @@ M.clone = {
76
77
end ,
77
78
}
78
79
80
+ -- setup origin branches if needed
81
+ -- fetch will retrieve the data
79
82
M .branch = {
80
83
skip = function (plugin )
81
84
if not plugin ._ .installed or plugin ._ .is_local then
82
85
return true
83
86
end
84
87
local branch = assert (Git .get_branch (plugin ))
85
- return branch and branch . commit
88
+ return Git . get_commit ( plugin . dir , branch )
86
89
end ,
87
90
run = function (self )
88
- local branch = assert (Git .get_branch (self .plugin ))
89
91
local args = {
90
92
" remote" ,
91
93
" set-branches" ,
92
94
" --add" ,
93
95
" origin" ,
94
- branch . branch ,
96
+ assert ( Git . get_branch ( self . plugin )) ,
95
97
}
96
98
97
99
self :spawn (" git" , {
@@ -101,6 +103,7 @@ M.branch = {
101
103
end ,
102
104
}
103
105
106
+ -- fetches all needed origin branches
104
107
M .fetch = {
105
108
skip = function (plugin )
106
109
return not plugin ._ .installed or plugin ._ .is_local
@@ -121,6 +124,8 @@ M.fetch = {
121
124
end ,
122
125
}
123
126
127
+ -- checkout to the target commit
128
+ -- branches will exists at this point, so so will the commit
124
129
M .checkout = {
125
130
skip = function (plugin )
126
131
return not plugin ._ .installed or plugin ._ .is_local
@@ -131,21 +136,24 @@ M.checkout = {
131
136
local info = assert (Git .info (self .plugin .dir ))
132
137
local target = assert (Git .get_target (self .plugin ))
133
138
134
- -- if the plugin is locked and we did not just clone it,
139
+ -- if the plugin is pinned and we did not just clone it,
135
140
-- then don't update
136
141
if self .plugin .pin and not self .plugin ._ .cloned then
137
142
target = info
138
143
end
139
144
140
145
local lock
141
146
if opts .lockfile then
147
+ -- restore to the lock if it exists
142
148
lock = Lock .get (self .plugin )
143
149
if lock then
144
150
--- @diagnostic disable-next-line : cast-local-type
145
151
target = lock
146
152
end
147
153
end
148
154
155
+ -- dont run checkout if target is already reached.
156
+ -- unless we just clones, since then we won't have any data yet
149
157
if not self .plugin ._ .cloned and info .commit == target .commit and info .branch == target .branch then
150
158
self .plugin ._ .updated = {
151
159
from = info .commit ,
@@ -165,8 +173,8 @@ M.checkout = {
165
173
table.insert (args , " tags/" .. target .tag )
166
174
elseif self .plugin .commit then
167
175
table.insert (args , self .plugin .commit )
168
- elseif target . branch then
169
- table.insert (args , target .branch )
176
+ else
177
+ table.insert (args , target .commit )
170
178
end
171
179
172
180
self :spawn (" git" , {
0 commit comments