@@ -597,7 +597,8 @@ function Plugin.new(spec)
597
597
is_remote = not name :find (vim .env .HOME ), -- Is it a remote or local plugin
598
598
is_local = spec .is_local or false , -- Development mode flag
599
599
is_lazy = spec .is_lazy or false , -- Whether to lazy load
600
- local_path = nil , -- Loacal path to load
600
+ local_path = nil , -- Local path to load
601
+ branch = spec .branch , -- Git branch to use
601
602
602
603
-- States
603
604
status = STATUS .PENDING , -- Current plugin status
@@ -765,7 +766,11 @@ function Plugin:load(do_action, callback)
765
766
end
766
767
767
768
if do_action and self .run_action then
768
- vim .cmd (self .run_action )
769
+ if type (self .run_action ) == ' string' then
770
+ vim .cmd (self .run_action )
771
+ else
772
+ self .run_action ()
773
+ end
769
774
end
770
775
771
776
if callback then
@@ -944,14 +949,17 @@ function Plugin:keys(mappings)
944
949
if type (rhs ) == ' function' then
945
950
self :load (nil , rhs )
946
951
elseif type (rhs ) == ' string' then
947
- self :load (nil , function () vim .cmd (rhs ) end )
952
+ self :load (nil , function ()
953
+ vim .cmd (rhs )
954
+ end )
948
955
elseif type (rhs ) == ' nil' then
949
956
-- If rhs not specified, it should be defined in plugin config
950
957
-- In this case, we need to pass a callback
951
958
self :load (nil , function ()
952
959
vim .schedule (function ()
953
960
vim .fn .feedkeys (lhs )
954
- end ) end )
961
+ end )
962
+ end )
955
963
end
956
964
end , opts )
957
965
end
@@ -992,6 +1000,17 @@ function Plugin:after(fn)
992
1000
return self
993
1001
end
994
1002
1003
+ function Plugin :branch (branch_name )
1004
+ assert (
1005
+ type (branch_name ) == ' string' and branch_name ~= ' ' ,
1006
+ ' Branch name must be a non-empty string'
1007
+ )
1008
+ self .branch = branch_name
1009
+ return self
1010
+ end
1011
+
1012
+ function Plugin :bind () end
1013
+
995
1014
-- Set plugin as a theme
996
1015
function Plugin :theme (name )
997
1016
self .colorscheme = name or self .plugin_name
@@ -1026,7 +1045,7 @@ function Plugin:call_setup()
1026
1045
end
1027
1046
1028
1047
function Plugin :run (action )
1029
- assert (type (action ) == ' string' )
1048
+ assert (type (action ) == ' string' or type ( action ) == ' function ' )
1030
1049
self .run_action = action
1031
1050
return self
1032
1051
end
@@ -1045,7 +1064,7 @@ function Plugin:depends(deps)
1045
1064
return self
1046
1065
end
1047
1066
1048
- -- Install the plugin
1067
+ -- MODIFIED: Install the plugin with branch support
1049
1068
function Plugin :install ()
1050
1069
if self .is_local or not self .is_remote then
1051
1070
return Async .wrap (function (cb )
@@ -1063,13 +1082,23 @@ function Plugin:install()
1063
1082
' --depth=' .. DEFAULT_SETTINGS .git_depth ,
1064
1083
' --single-branch' ,
1065
1084
' --progress' ,
1066
- url ,
1067
- path ,
1068
1085
}
1069
1086
1087
+ -- Add branch specification if provided
1088
+ if self .branch then
1089
+ table.insert (cmd , ' --branch=' .. self .branch )
1090
+ M .log (' debug' , string.format (' Installing %s from branch: %s' , self .name , self .branch ))
1091
+ end
1092
+
1093
+ -- Add URL and path at the end
1094
+ table.insert (cmd , url )
1095
+ table.insert (cmd , path )
1096
+
1070
1097
-- Update status
1071
1098
self .status = STATUS .INSTALLING
1072
- ui :update_entry (self .name , self .status , ' Starting installation...' )
1099
+ local install_msg = self .branch and (' Installing from branch: ' .. self .branch )
1100
+ or ' Starting installation...'
1101
+ ui :update_entry (self .name , self .status , install_msg )
1073
1102
1074
1103
-- Use our new Async.system wrapper
1075
1104
local result = Async .try_await (Async .system (cmd , {
@@ -1091,7 +1120,9 @@ function Plugin:install()
1091
1120
1092
1121
if result .success then
1093
1122
self .status = STATUS .INSTALLED
1094
- ui :update_entry (self .name , self .status , ' Installation complete' )
1123
+ local success_msg = self .branch and (' Installed from branch: ' .. self .branch )
1124
+ or ' Installation complete'
1125
+ ui :update_entry (self .name , self .status , success_msg )
1095
1126
1096
1127
-- Apply colorscheme if this is a theme
1097
1128
if self .colorscheme then
@@ -1114,6 +1145,7 @@ function Plugin:install()
1114
1145
end )()
1115
1146
end
1116
1147
1148
+ -- MODIFIED: Check for updates with branch awareness
1117
1149
function Plugin :has_updates ()
1118
1150
return Async .wrap (function (callback )
1119
1151
if self .is_local or not self .is_remote then
@@ -1131,19 +1163,26 @@ function Plugin:has_updates()
1131
1163
' origin' ,
1132
1164
}
1133
1165
1166
+ -- If a specific branch is set, fetch that branch
1167
+ if self .branch then
1168
+ table.insert (fetch_cmd , self .branch .. ' :refs/remotes/origin/' .. self .branch )
1169
+ end
1170
+
1134
1171
local result = Async .try_await (Async .system (fetch_cmd ))
1135
1172
if not result .success then
1136
1173
callback (false )
1137
1174
return
1138
1175
end
1139
1176
1177
+ -- Compare with the appropriate upstream
1178
+ local upstream_ref = self .branch and ' @{upstream}' or ' @{upstream}'
1140
1179
local rev_cmd = {
1141
1180
' git' ,
1142
1181
' -C' ,
1143
1182
path ,
1144
1183
' rev-list' ,
1145
1184
' --count' ,
1146
- ' HEAD..@{upstream} ' ,
1185
+ ' HEAD..' .. upstream_ref ,
1147
1186
}
1148
1187
1149
1188
result = Async .try_await (Async .system (rev_cmd ))
@@ -1159,6 +1198,7 @@ function Plugin:has_updates()
1159
1198
end )()
1160
1199
end
1161
1200
1201
+ -- MODIFIED: Update plugin with branch support
1162
1202
function Plugin :update (skip_check )
1163
1203
if self .is_local or not self .is_remote then
1164
1204
return Async .wrap (function (cb )
@@ -1209,19 +1249,29 @@ function Plugin:update(skip_check)
1209
1249
1210
1250
if not has_updates then
1211
1251
self .status = STATUS .UPDATED
1212
- ui :update_entry (self .name , self .status , ' Already up to date' )
1252
+ local up_to_date_msg = self .branch and (' Up to date on branch: ' .. self .branch )
1253
+ or ' Already up to date'
1254
+ ui :update_entry (self .name , self .status , up_to_date_msg )
1213
1255
callback (true , ' up_to_date' )
1214
1256
return
1215
1257
end
1216
1258
end
1217
1259
1218
1260
-- Update the plugin
1219
1261
self .status = STATUS .UPDATING
1220
- ui :update_entry (self .name , self .status , ' Starting update...' )
1262
+ local updating_msg = self .branch and (' Updating branch: ' .. self .branch )
1263
+ or ' Starting update...'
1264
+ ui :update_entry (self .name , self .status , updating_msg )
1221
1265
1222
1266
local path = self :get_path ()
1223
1267
local cmd = { ' git' , ' -C' , path , ' pull' , ' --progress' }
1224
1268
1269
+ -- If specific branch is set, pull from that branch
1270
+ if self .branch then
1271
+ table.insert (cmd , ' origin' )
1272
+ table.insert (cmd , self .branch )
1273
+ end
1274
+
1225
1275
-- Use our new Async.system wrapper
1226
1276
local result = Async .try_await (Async .system (cmd , {
1227
1277
timeout = DEFAULT_SETTINGS .git_timeout ,
@@ -1246,10 +1296,15 @@ function Plugin:update(skip_check)
1246
1296
local stdout = result .value .stdout or ' '
1247
1297
local update_info = ' Update complete'
1248
1298
local commit_info = stdout :match (' ([a-f0-9]+)%.%.([a-f0-9]+)' )
1299
+
1249
1300
if stdout :find (' Already up to date' ) then
1250
- update_info = ' Already up to date'
1301
+ update_info = self .branch and (' Already up to date on branch: ' .. self .branch )
1302
+ or ' Already up to date'
1251
1303
elseif commit_info then
1252
- update_info = string.format (' Updated to %s' , stdout :match (' ([a-f0-9]+)%.%.([a-f0-9]+)' ))
1304
+ local branch_info = self .branch and (' on branch: ' .. self .branch ) or ' '
1305
+ update_info = string.format (' Updated to %s%s' , commit_info , branch_info )
1306
+ elseif self .branch then
1307
+ update_info = ' Updated on branch: ' .. self .branch
1253
1308
end
1254
1309
1255
1310
ui :update_entry (self .name , self .status , update_info )
@@ -1263,6 +1318,7 @@ function Plugin:update(skip_check)
1263
1318
end )()
1264
1319
end
1265
1320
1321
+ -- MODIFIED: Install with retry and branch support
1266
1322
function Plugin :install_with_retry ()
1267
1323
if self .is_local or not self .is_remote then
1268
1324
return Async .wrap (function (cb )
@@ -1279,11 +1335,21 @@ function Plugin:install_with_retry()
1279
1335
end
1280
1336
1281
1337
self .status = STATUS .INSTALLING
1282
- ui :update_entry (self .name , self .status , ' Starting installation...' )
1338
+ local install_msg = self .branch and (' Installing from branch: ' .. self .branch )
1339
+ or ' Starting installation...'
1340
+ ui :update_entry (self .name , self .status , install_msg )
1283
1341
1284
1342
local path = self :get_path ()
1285
1343
local url = (' https://github.com/%s' ):format (self .name )
1286
- local cmd = { ' git' , ' clone' , ' --progress' , url , path }
1344
+ local cmd = { ' git' , ' clone' , ' --progress' }
1345
+
1346
+ -- Add branch specification if provided
1347
+ if self .branch then
1348
+ table.insert (cmd , ' --branch=' .. self .branch )
1349
+ end
1350
+
1351
+ table.insert (cmd , url )
1352
+ table.insert (cmd , path )
1287
1353
1288
1354
-- Use retry with the system command (3 retries with exponential backoff)
1289
1355
local result = Async .try_await (Async .retry (function ()
@@ -1308,7 +1374,9 @@ function Plugin:install_with_retry()
1308
1374
-- Handle result
1309
1375
if result .success then
1310
1376
self .status = STATUS .INSTALLED
1311
- ui :update_entry (self .name , self .status , ' Installation complete' )
1377
+ local success_msg = self .branch and (' Installed from branch: ' .. self .branch )
1378
+ or ' Installation complete'
1379
+ ui :update_entry (self .name , self .status , success_msg )
1312
1380
1313
1381
-- Apply colorscheme if this is a theme
1314
1382
if self .colorscheme then
@@ -1418,7 +1486,7 @@ function M.install()
1418
1486
table.insert (install_tasks , function (done )
1419
1487
Async .async (function ()
1420
1488
local result = Async .try_await (
1421
- DEFAULT_SETTINGS .install_retry and Plugin :install_with_retry () or plugin :install ()
1489
+ DEFAULT_SETTINGS .install_retry and plugin :install_with_retry () or plugin :install ()
1422
1490
)
1423
1491
if not result .success then
1424
1492
M .log (
0 commit comments