@@ -12,17 +12,27 @@ namespace Common.Utilities
1212{
1313 public static class ContextExtensions
1414 {
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 )
1616 {
1717 var processSettings = new ProcessSettings { Arguments = args , RedirectStandardOutput = true } ;
18+ if ( workDir is not null )
19+ {
20+ processSettings . WorkingDirectory = workDir ;
21+ }
1822 context . StartProcess ( exe , processSettings , out var redirectedOutput ) ;
1923 return redirectedOutput . ToList ( ) ;
2024 }
2125
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 )
2327 {
2428 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 ) ;
2636 }
2737
2838 public static bool IsOriginalRepo ( this ICakeContext context )
@@ -49,7 +59,7 @@ public static bool IsOriginalRepo(this ICakeContext context)
4959 public static bool IsMainBranch ( this ICakeContext context )
5060 {
5161 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 ( ) ;
5363 if ( buildSystem . IsRunningOnAppVeyor )
5464 {
5565 repositoryBranch = buildSystem . AppVeyor . Environment . Repository . Branch ;
@@ -70,8 +80,8 @@ public static bool IsMainBranch(this ICakeContext context)
7080
7181 public static bool IsTagged ( this ICakeContext context )
7282 {
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 ( ) ;
7585
7686 return isTagged ;
7787 }
0 commit comments