@@ -12,17 +12,27 @@ namespace Common.Utilities
12
12
{
13
13
public static class ContextExtensions
14
14
{
15
- private static IEnumerable < string > ExecuteCommand ( this ICakeContext context , FilePath exe , string ? args )
15
+ private static IEnumerable < string > ExecuteCommand ( this ICakeContext context , FilePath exe , string ? args , DirectoryPath ? workDir = null )
16
16
{
17
17
var processSettings = new ProcessSettings { Arguments = args , RedirectStandardOutput = true } ;
18
+ if ( workDir is not null )
19
+ {
20
+ processSettings . WorkingDirectory = workDir ;
21
+ }
18
22
context . StartProcess ( exe , processSettings , out var redirectedOutput ) ;
19
23
return redirectedOutput . ToList ( ) ;
20
24
}
21
25
22
- private static IEnumerable < string > ExecGitCmd ( this ICakeContext context , string ? cmd )
26
+ private static IEnumerable < string > ExecGitCmd ( this ICakeContext context , string ? cmd , DirectoryPath ? workDir = null )
23
27
{
24
28
var gitExe = context . Tools . Resolve ( context . IsRunningOnWindows ( ) ? "git.exe" : "git" ) ;
25
- return context . ExecuteCommand ( gitExe , cmd ) ;
29
+ return context . ExecuteCommand ( gitExe , cmd , workDir ) ;
30
+ }
31
+
32
+ public static void GitPushBranch ( this ICakeContext context , DirectoryPath repositoryDirectoryPath , string username , string token , string branchName )
33
+ {
34
+ var pushUrl = $ "https://{ username } :{ token } @github.com/{ Constants . RepoOwner } /{ Constants . Repository } ";
35
+ context . ExecGitCmd ( $ "push { pushUrl } { branchName } ", workDir : repositoryDirectoryPath ) ;
26
36
}
27
37
28
38
public static bool IsOriginalRepo ( this ICakeContext context )
@@ -49,7 +59,7 @@ public static bool IsOriginalRepo(this ICakeContext context)
49
59
public static bool IsMainBranch ( this ICakeContext context )
50
60
{
51
61
var buildSystem = context . BuildSystem ( ) ;
52
- string repositoryBranch = ExecGitCmd ( context , "rev-parse --abbrev-ref HEAD" ) . Single ( ) ;
62
+ string repositoryBranch = context . ExecGitCmd ( "rev-parse --abbrev-ref HEAD" ) . Single ( ) ;
53
63
if ( buildSystem . IsRunningOnAppVeyor )
54
64
{
55
65
repositoryBranch = buildSystem . AppVeyor . Environment . Repository . Branch ;
@@ -70,8 +80,8 @@ public static bool IsMainBranch(this ICakeContext context)
70
80
71
81
public static bool IsTagged ( this ICakeContext context )
72
82
{
73
- var sha = ExecGitCmd ( context , "rev-parse --verify HEAD" ) . Single ( ) ;
74
- var isTagged = ExecGitCmd ( context , "tag --points-at " + sha ) . Any ( ) ;
83
+ var sha = context . ExecGitCmd ( "rev-parse --verify HEAD" ) . Single ( ) ;
84
+ var isTagged = context . ExecGitCmd ( "tag --points-at " + sha ) . Any ( ) ;
75
85
76
86
return isTagged ;
77
87
}
0 commit comments