@@ -1276,6 +1276,7 @@ function GitAdapter:diffview_options(argo)
12761276 local left , right = self :parse_revs (rev_arg , {
12771277 cached = argo :get_flag ({ " cached" , " staged" }),
12781278 imply_local = argo :get_flag (" imply-local" ),
1279+ merge_base = argo :get_flag (" merge-base" ),
12791280 })
12801281
12811282 if not (left and right ) then
@@ -1453,10 +1454,26 @@ function GitAdapter:parse_revs(rev_arg, opt)
14531454 end
14541455 else
14551456 local hash = rev_strings [1 ]:gsub (" ^%^" , " " )
1456- left = GitRev (RevType .COMMIT , hash )
14571457 if opt .cached then
1458+ left = GitRev (RevType .COMMIT , hash )
14581459 right = GitRev (RevType .STAGE , 0 )
14591460 else
1461+ -- When comparing a single ref with working tree, optionally use merge-base
1462+ if opt .merge_base then
1463+ local merge_base_out , merge_base_code = self :exec_sync (
1464+ { " merge-base" , " HEAD" , hash },
1465+ { cwd = self .ctx .toplevel , fail_on_empty = true , retry = 2 }
1466+ )
1467+ if merge_base_code == 0 and # merge_base_out > 0 then
1468+ -- Use merge-base as the left side
1469+ left = GitRev (RevType .COMMIT , merge_base_out [1 ])
1470+ else
1471+ -- Fallback to the ref itself if merge-base fails
1472+ left = GitRev (RevType .COMMIT , hash )
1473+ end
1474+ else
1475+ left = GitRev (RevType .COMMIT , hash )
1476+ end
14601477 right = GitRev (RevType .LOCAL )
14611478 end
14621479 end
@@ -2127,6 +2144,7 @@ function GitAdapter:init_completion()
21272144 self .comp .open :put ({ " u" , " untracked-files" }, { " true" , " normal" , " all" , " false" , " no" })
21282145 self .comp .open :put ({ " cached" , " staged" })
21292146 self .comp .open :put ({ " imply-local" })
2147+ self .comp .open :put ({ " merge-base" })
21302148 self .comp .open :put ({ " C" }, function (_ , arg_lead )
21312149 return vim .fn .getcompletion (arg_lead , " dir" )
21322150 end )
0 commit comments