Skip to content

Commit 36aeb3f

Browse files
committed
feature: supports CLI command --file-history <file_path> to view given file history (#1892)
Signed-off-by: leo <[email protected]>
1 parent 4c38170 commit 36aeb3f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/App.axaml.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ public override void OnFrameworkInitializationCompleted()
387387
e.Cancel = true;
388388
});
389389

390+
if (TryLaunchAsFileHistoryViewer(desktop))
391+
return;
392+
390393
if (TryLaunchAsCoreEditor(desktop))
391394
return;
392395

@@ -513,6 +516,33 @@ private static bool TryLaunchAsRebaseMessageEditor(string[] args, out int exitCo
513516
return true;
514517
}
515518

519+
private bool TryLaunchAsFileHistoryViewer(IClassicDesktopStyleApplicationLifetime desktop)
520+
{
521+
var args = desktop.Args;
522+
if (args is not { Length: > 1 } || !args[0].Equals("--file-history", StringComparison.Ordinal))
523+
return false;
524+
525+
var file = Path.GetFullPath(args[1]);
526+
var dir = Path.GetDirectoryName(file);
527+
528+
var test = new Commands.QueryRepositoryRootPath(dir).GetResult();
529+
if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut))
530+
{
531+
Console.Out.WriteLine($"'{args[1]}' is not in a valid git repository");
532+
desktop.Shutdown(-1);
533+
return true;
534+
}
535+
536+
var repo = test.StdOut.Trim();
537+
var relFile = Path.GetRelativePath(repo, file);
538+
var viewer = new Views.FileHistories()
539+
{
540+
DataContext = new ViewModels.FileHistories(repo, relFile)
541+
};
542+
desktop.MainWindow = viewer;
543+
return true;
544+
}
545+
516546
private bool TryLaunchAsCoreEditor(IClassicDesktopStyleApplicationLifetime desktop)
517547
{
518548
var args = desktop.Args;

0 commit comments

Comments
 (0)