MCPcopy Create free account
hub / github.com/angular/dev-infra / runGraceful

Method runGraceful

ng-dev/utils/testing/sandbox-git-client.ts:42–70  ·  view source on GitHub ↗

Override for the actual Git client command execution.

(args: string[], options: SpawnSyncOptions = {})

Source from the content-addressed store, hash-verified

40
41 /** Override for the actual Git client command execution. */
42 override runGraceful(args: string[], options: SpawnSyncOptions = {}): SpawnSyncReturns<string> {
43 const command = args[0];
44
45 // If any command refers to `FETCH_HEAD` in some way, we always
46 // return the noop spawn sync value. We do not deal with remotes
47 // in the sandbox client so this would always fail.
48 if (args.some((v) => v.includes('FETCH_HEAD'))) {
49 return noopSpawnSyncReturns;
50 }
51
52 // For the following commands, we do not run Git as those deal with
53 // remotes and we do not allow this for the sandboxed environment.
54 if (command === 'push' || command === 'fetch') {
55 return noopSpawnSyncReturns;
56 }
57
58 // When ls-remote is run in our testing environment we are always
59 // checking for an already defined ref which "should exist upstream"
60 // Since no upstream exists in testing, we just check to make sure
61 // the ref has already been defined locally by changing the git remote
62 // provided to '.' which points to the local git repo.
63 if (command === 'ls-remote') {
64 const gitRemoteMatcher =
65 /((git|ssh|http(s)?)|(git@[\w\.]+))(:(\/\/)?)([\w\.@\:/\-~]+)(\.git)(\/)?/;
66 args = args.map((arg) => (gitRemoteMatcher.test(arg) ? '.' : arg));
67 }
68
69 return super.runGraceful(args, options);
70 }
71}
72
73export function installSandboxGitClient(mockInstance: SandboxGitClient) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected