Skip to content

Commit 446f24f

Browse files
committed
add working-directory argument
1 parent 15fc5e9 commit 446f24f

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

GitContentSearch/GitHelper.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ namespace GitContentSearch
55
public class GitHelper : IGitHelper
66
{
77
private readonly IProcessWrapper _processWrapper;
8+
private readonly string? _workingDirectory;
89

910
public GitHelper(IProcessWrapper processWrapper)
1011
{
1112
_processWrapper = processWrapper;
1213
}
1314

15+
public GitHelper(IProcessWrapper processWrapper, string? workingDirectory)
16+
{
17+
_processWrapper = processWrapper;
18+
_workingDirectory = workingDirectory;
19+
}
20+
1421
public string GetCommitTime(string commitHash)
1522
{
1623
var startInfo = new ProcessStartInfo
@@ -20,7 +27,8 @@ public string GetCommitTime(string commitHash)
2027
RedirectStandardOutput = true,
2128
RedirectStandardError = true,
2229
UseShellExecute = false,
23-
CreateNoWindow = true
30+
CreateNoWindow = true,
31+
WorkingDirectory = _workingDirectory // Set the working directory
2432
};
2533

2634
var result = _processWrapper.Start(startInfo);
@@ -50,7 +58,8 @@ public void RunGitShow(string commit, string filePath, string outputFile)
5058
RedirectStandardOutput = true,
5159
RedirectStandardError = true,
5260
UseShellExecute = false,
53-
CreateNoWindow = true
61+
CreateNoWindow = true,
62+
WorkingDirectory = _workingDirectory // Set the working directory
5463
};
5564

5665
ProcessResult result;
@@ -74,7 +83,8 @@ public string[] GetGitCommits(string earliest, string latest)
7483
RedirectStandardOutput = true,
7584
RedirectStandardError = true,
7685
UseShellExecute = false,
77-
CreateNoWindow = true
86+
CreateNoWindow = true,
87+
WorkingDirectory = _workingDirectory // Set the working directory
7888
};
7989

8090
var result = _processWrapper.Start(startInfo);

GitContentSearch/Program.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ static void Main(string[] args)
99
{
1010
if (args.Length < 2)
1111
{
12-
Console.WriteLine("Usage: <program> <file-path> <search-string> [--earliest-commit=<commit>] [--latest-commit=<commit>]");
12+
Console.WriteLine("Usage: <program> <file-path> <search-string> [--earliest-commit=<commit>] [--latest-commit=<commit>] [--working-directory=<path>]");
1313
return;
1414
}
1515

1616
string filePath = args[0];
1717
string searchString = args[1];
1818
string earliestCommit = "";
1919
string latestCommit = "";
20+
string? workingDirectory = null;
2021

2122
// Parse optional arguments
2223
foreach (var arg in args.Skip(2))
@@ -29,10 +30,14 @@ static void Main(string[] args)
2930
{
3031
latestCommit = arg.Replace("--latest-commit=", "");
3132
}
33+
else if (arg.StartsWith("--working-directory="))
34+
{
35+
workingDirectory = arg.Replace("--working-directory=", "");
36+
}
3237
}
3338

3439
var processWrapper = new ProcessWrapper();
35-
var gitHelper = new GitHelper(processWrapper);
40+
var gitHelper = new GitHelper(processWrapper, workingDirectory);
3641
var fileSearcher = new FileSearcher();
3742
var gitContentSearcher = new GitContentSearcher(gitHelper, fileSearcher, new FileManager());
3843
gitContentSearcher.SearchContent(filePath, searchString, earliestCommit, latestCommit);

0 commit comments

Comments
 (0)