From 687da9f3dce8310dbcc1da865c737ad467caa4fb Mon Sep 17 00:00:00 2001
From: Julius Lehmann <lehmanju@devpi.de>
Date: Tue, 28 May 2024 09:04:21 +0200
Subject: [PATCH] output stderr

---
 dist/index.js              | 20 +++++++-------------
 src/git-auth-helper.ts     |  3 ---
 src/git-command-manager.ts | 19 +++++++------------
 3 files changed, 14 insertions(+), 28 deletions(-)

diff --git a/dist/index.js b/dist/index.js
index 4f2181b..5978ceb 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -356,9 +356,6 @@ class GitAuthHelper {
             if (!configPath && !globalConfig) {
                 configPath = path.join(this.git.getWorkingDirectory(), '.git', 'config');
             }
-            // Configure a placeholder value. This approach avoids the credential being captured
-            // by process creation audit events, which are commonly logged. For more information,
-            // refer to https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/manage/component-updates/command-line-process-auditing
             yield this.git.config(this.tokenConfigKey, `"store --file ${this.credentialStorePath}"`, globalConfig);
         });
     }
@@ -874,24 +871,20 @@ class GitCommandManager {
             for (const key of Object.keys(this.gitEnv)) {
                 env[key] = this.gitEnv[key];
             }
-            const defaultListener = {
-                stdout: (data) => {
-                    stdout.push(data.toString());
-                }
-            };
-            const mergedListeners = Object.assign(Object.assign({}, defaultListener), customListeners);
-            const stdout = [];
             const options = {
                 cwd: this.workingDirectory,
                 env,
                 silent,
                 ignoreReturnCode: allowAllExitCodes,
-                listeners: mergedListeners
+                listeners: customListeners
             };
-            result.exitCode = yield exec.exec(`"${this.gitPath}"`, args, options);
-            result.stdout = stdout.join('');
+            let execOutput = yield exec.getExecOutput(`"${this.gitPath}"`, args, options);
+            result.exitCode = execOutput.exitCode;
+            result.stdout = execOutput.stdout;
+            result.stderr = execOutput.stderr;
             core.debug(result.exitCode.toString());
             core.debug(result.stdout);
+            core.debug(result.stderr);
             return result;
         });
     }
@@ -963,6 +956,7 @@ class GitCommandManager {
 class GitOutput {
     constructor() {
         this.stdout = '';
+        this.stderr = '';
         this.exitCode = 0;
     }
 }
diff --git a/src/git-auth-helper.ts b/src/git-auth-helper.ts
index 1831df8..606e999 100644
--- a/src/git-auth-helper.ts
+++ b/src/git-auth-helper.ts
@@ -276,9 +276,6 @@ class GitAuthHelper {
       configPath = path.join(this.git.getWorkingDirectory(), '.git', 'config')
     }
 
-    // Configure a placeholder value. This approach avoids the credential being captured
-    // by process creation audit events, which are commonly logged. For more information,
-    // refer to https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/manage/component-updates/command-line-process-auditing
     await this.git.config(
       this.tokenConfigKey,
       `"store --file ${this.credentialStorePath}"`,
diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts
index 8e42a38..71bd2ba 100644
--- a/src/git-command-manager.ts
+++ b/src/git-command-manager.ts
@@ -522,28 +522,22 @@ class GitCommandManager {
       env[key] = this.gitEnv[key]
     }
 
-    const defaultListener = {
-      stdout: (data: Buffer) => {
-        stdout.push(data.toString())
-      }
-    }
-
-    const mergedListeners = {...defaultListener, ...customListeners}
-
-    const stdout: string[] = []
     const options = {
       cwd: this.workingDirectory,
       env,
       silent,
       ignoreReturnCode: allowAllExitCodes,
-      listeners: mergedListeners
+      listeners: customListeners
     }
 
-    result.exitCode = await exec.exec(`"${this.gitPath}"`, args, options)
-    result.stdout = stdout.join('')
+    let execOutput = await exec.getExecOutput(`"${this.gitPath}"`, args, options)
+    result.exitCode = execOutput.exitCode
+    result.stdout = execOutput.stdout
+    result.stderr = execOutput.stderr
 
     core.debug(result.exitCode.toString())
     core.debug(result.stdout)
+    core.debug(result.stderr)
 
     return result
   }
@@ -631,5 +625,6 @@ class GitCommandManager {
 
 class GitOutput {
   stdout = ''
+  stderr = ''
   exitCode = 0
 }