1
1
local eq = assert .are .same
2
2
local status = require (" neogit.status" )
3
3
local harness = require (" tests.util.git_harness" )
4
+ local system = require (" tests.util.util" ).system
4
5
local _ = require (" tests.mocks.input" )
5
6
local in_prepared_repo = harness .in_prepared_repo
6
7
local get_git_status = harness .get_git_status
@@ -17,10 +18,7 @@ local function find(text)
17
18
for index , line in ipairs (vim .api .nvim_buf_get_lines (0 , 0 , - 1 , true )) do
18
19
if line :match (text ) then
19
20
vim .api .nvim_win_set_cursor (0 , { index , 0 })
20
- -- print(">" .. tostring(index) .. " " .. line)
21
- break
22
- -- else
23
- -- print(tostring(index) .. " " .. line)
21
+ return unpack { line , index }
24
22
end
25
23
end
26
24
end
@@ -307,4 +305,99 @@ describe("status buffer", function()
307
305
end )
308
306
)
309
307
end )
308
+
309
+ describe (" recent commits" , function ()
310
+ local recent_commit_pattern = " Recent commits %(%d+%)"
311
+
312
+ local function refresh_status_buffer ()
313
+ act (" <c-r>" )
314
+ require (" plenary.async" ).util .block_on (status .reset )
315
+ end
316
+
317
+ local function create_new_commits (message , number_of_commits , original_commit_count )
318
+ system (" git stash && git stash clear && git clean -ffdx" )
319
+ system (
320
+ string.format (
321
+ " COUNT=0; while ((COUNT < %s)) do; printf 'Some Content\n ' >> a-file && git add a-file && git commit -m '%s' && ((COUNT++)); done" ,
322
+ number_of_commits ,
323
+ message
324
+ ),
325
+ true
326
+ )
327
+ refresh_status_buffer ()
328
+ end
329
+
330
+ describe (" count" , function ()
331
+ it (
332
+ " has the correct number of recent commits" ,
333
+ in_prepared_repo (function ()
334
+ local line = find (recent_commit_pattern )
335
+ local recent_commit_count = tonumber (string.match (line , " %d+" ))
336
+ local repo_commit_count = tonumber (system (" git rev-list master --count" ))
337
+ assert .are .equal (recent_commit_count , repo_commit_count )
338
+ end )
339
+ )
340
+
341
+ it (
342
+ " has the correct number when there are more commits than recent_commit_count" ,
343
+ in_prepared_repo (function ()
344
+ create_new_commits (" A commit to increase commit number" , 50 )
345
+ local line = find (recent_commit_pattern )
346
+ local recent_commit_count = tonumber (string.match (line , " %d+" ))
347
+ local repo_commit_count = tonumber (system (" git rev-list master --count" ))
348
+ local config_commit_count = require (" neogit.config" ).values .status .recent_commit_count
349
+
350
+ -- Ensures the actual number of recent commits is less than the repo commits.
351
+ -- The total number of repo commits SHOULD be more than the recent commit count.
352
+ print (" Recent Commit Count: " .. recent_commit_count )
353
+ print (" Repository Commit Count: " .. repo_commit_count )
354
+ assert .True (recent_commit_count < repo_commit_count )
355
+ -- Ensure the number of recent commits is equal to the number specified in the config
356
+ assert .are .equal (recent_commit_count , config_commit_count )
357
+ end )
358
+ )
359
+ end )
360
+ describe (" content" , function ()
361
+ local function get_latest_recent_commit ()
362
+ -- Get the commit right under the "Recent commits" message
363
+ local _ , cursor_row = find (recent_commit_pattern )
364
+ act (" <tab>" )
365
+ vim .api .nvim_win_set_cursor (0 , { cursor_row + 1 , 0 })
366
+ local commit_message_line = vim .api .nvim_buf_get_lines (0 , cursor_row , cursor_row + 1 , true )[1 ]
367
+ -- Remove the leading commit hash
368
+ local commit_message = string.gsub (commit_message_line , " ^[a-z0-9]+ " , " " )
369
+
370
+ return commit_message
371
+ end
372
+
373
+ it (
374
+ " has correct recent commit information with the default config" ,
375
+ in_prepared_repo (function ()
376
+ local new_commit_message = " a commit"
377
+ create_new_commits (new_commit_message , 1 )
378
+
379
+ local commit_message = get_latest_recent_commit ()
380
+ print (" Got commit message as: " .. commit_message )
381
+
382
+ assert .are .same (new_commit_message , commit_message )
383
+ end )
384
+ )
385
+
386
+ it (
387
+ " has correct recent commit information with extra author info" ,
388
+ in_prepared_repo (function ()
389
+ require (" neogit.config" ).values .status .recent_commit_include_author_info = true
390
+ local new_commit_message = " a commit"
391
+ create_new_commits (new_commit_message , 1 )
392
+
393
+ local commit_message = get_latest_recent_commit ()
394
+ print (" Got commit message as: " .. commit_message )
395
+
396
+ new_commit_message =
397
+ string.format (" [%s] <%s> %s" , " Neogit Test User" , " test@neogit.git" , new_commit_message )
398
+ assert .are .same (new_commit_message , commit_message )
399
+ end )
400
+ )
401
+ end )
402
+ end )
310
403
end )
0 commit comments