1
1
using AddActionsWorkflow . Options ;
2
2
using CliWrap ;
3
3
using LibGit2Sharp ;
4
+ using Microsoft ;
4
5
using System . Diagnostics ;
5
6
using System . IO ;
7
+ using System . Linq ;
6
8
using System . Text ;
7
9
using System . Threading . Tasks ;
8
10
@@ -48,12 +50,12 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
48
50
proj = await sln . AddSolutionFolderAsync ( options . SolutionFolderName ) ;
49
51
50
52
_ = await proj ? . AddExistingFilesAsync ( Path . Combine ( slnDir , @$ ".github\workflows\{ finaleWorkflowname } .yaml") ) ;
51
- await VS . StatusBar . ShowMessageAsync ( "GitHub Actions Worklfow creation finished." ) ;
53
+ await VS . StatusBar . ShowMessageAsync ( "GitHub Actions Workflow creation finished." ) ;
52
54
}
53
55
else
54
56
{
55
57
// didn't happen, show an error
56
- await VS . StatusBar . ShowMessageAsync ( "GitHub Actions Worklfow creation failed." ) ;
58
+ await VS . StatusBar . ShowMessageAsync ( "GitHub Actions Workflow creation failed." ) ;
57
59
}
58
60
}
59
61
@@ -89,14 +91,11 @@ internal async Task<String> GetGitRootDirAsync(string workingDirectory, bool use
89
91
await VS . StatusBar . ShowMessageAsync ( "Establishing git root directory..." ) ;
90
92
var rootGitDir = workingDirectory ;
91
93
92
- while ( ! Directory . Exists ( Path . Combine ( rootGitDir , ".git" ) ) )
93
- {
94
- rootGitDir = Path . GetFullPath ( Path . Combine ( rootGitDir , ".." ) ) ;
95
- }
94
+ FindGitFolder ( rootGitDir , out string gitPath ) ;
96
95
97
96
try
98
97
{
99
- using ( var repo = new Repository ( rootGitDir ) )
98
+ using ( var repo = new Repository ( gitPath ) )
100
99
{
101
100
if ( useCurrentBranch ) branchName = repo . Head . FriendlyName ;
102
101
rootGitDir = repo . Info . WorkingDirectory ;
@@ -109,4 +108,24 @@ internal async Task<String> GetGitRootDirAsync(string workingDirectory, bool use
109
108
110
109
return rootGitDir ;
111
110
}
111
+
112
+ internal void FindGitFolder ( string path , out string foundPath )
113
+ {
114
+ foundPath = null ;
115
+ // Check if the current directory contains a .git folder
116
+ if ( Directory . Exists ( Path . Combine ( path , ".git" ) ) )
117
+ {
118
+ foundPath = path ;
119
+ return ;
120
+ }
121
+ else
122
+ {
123
+ string parentPath = Directory . GetParent ( path ) ? . FullName ;
124
+ if ( ! string . IsNullOrEmpty ( parentPath ) )
125
+ {
126
+ FindGitFolder ( parentPath , out foundPath ) ; // Recursively search the parent directory
127
+ }
128
+ }
129
+ return ;
130
+ }
112
131
}
0 commit comments