|
| 1 | +/* global require */ |
| 2 | + |
| 3 | +/* eslint-disable @typescript-eslint/no-require-imports */ |
1 | 4 | import * as vscode from "vscode"; |
2 | 5 |
|
3 | | -import * as child_process from "child_process"; |
4 | | -import * as util from "util"; |
5 | | -const execFile = util.promisify(child_process.execFile); |
| 6 | +import * as utils from "./utils"; |
| 7 | + |
| 8 | +// Set up execFile on desktop only |
| 9 | +type ExecFileType = ( |
| 10 | + cmd: string, |
| 11 | + args: string[], |
| 12 | +) => Promise<{ stdout: string; stderr: string }>; |
| 13 | +let execFile: ExecFileType | undefined; |
| 14 | +if (utils.isDesktopContext()) { |
| 15 | + const nodeUtil = require("util"); |
| 16 | + const child_process = require("child_process"); |
| 17 | + execFile = nodeUtil.promisify(child_process.execFile) as ExecFileType; |
| 18 | +} |
6 | 19 |
|
7 | 20 | /** Tell both Git and VSCode that commit messages should contain diffs */ |
8 | 21 | export async function enable() { |
9 | | - return Promise.all([ |
10 | | - // Set command line verbose-commits-by-default |
11 | | - execFile("git", ["config", "--global", "commit.verbose", "true"]), |
| 22 | + const promises = []; |
12 | 23 |
|
13 | | - // Tell VSCode to do verbose commits |
| 24 | + // Set command line verbose-commits-by-default only on desktop |
| 25 | + if (execFile) { |
| 26 | + promises.push( |
| 27 | + execFile("git", ["config", "--global", "commit.verbose", "true"]), |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + // Tell VSCode to do verbose commits |
| 32 | + promises.push( |
14 | 33 | vscode.workspace |
15 | 34 | .getConfiguration("git") |
16 | 35 | .update("verboseCommit", true, vscode.ConfigurationTarget.Global), |
17 | | - ]); |
| 36 | + ); |
| 37 | + |
| 38 | + return Promise.all(promises); |
18 | 39 | } |
19 | 40 |
|
20 | 41 | /** |
@@ -45,6 +66,11 @@ export function doesVsCodeDoVerboseCommits(): boolean { |
45 | 66 | } |
46 | 67 |
|
47 | 68 | export async function doesGitDoVerboseCommits(): Promise<boolean> { |
| 69 | + if (!execFile) { |
| 70 | + // Not desktop context, can't check git config, report that it doesn't need |
| 71 | + // changing |
| 72 | + return true; |
| 73 | + } |
48 | 74 | try { |
49 | 75 | const { stdout } = await execFile("git", [ |
50 | 76 | "config", |
|
0 commit comments