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

Method _checkout

ng-dev/utils/testing/virtual-git-client.ts:170–198  ·  view source on GitHub ↗

Handler for the `git checkout` command.

(rawArgs: string[])

Source from the content-addressed store, hash-verified

168
169 /** Handler for the `git checkout` command. */
170 private _checkout(rawArgs: string[]) {
171 const {
172 target,
173 B: createBranch,
174 detach: detached,
175 } = yargs(rawArgs)
176 .command('$0 <target>', false)
177 .positional('target', {demandOption: true, type: 'string'})
178 .option('detach', {boolean: true})
179 .option('q', {boolean: true})
180 .option('B', {boolean: true})
181 .parseSync();
182
183 if (target === 'FETCH_HEAD') {
184 if (this.fetchHeadRef === null) {
185 throw Error('Unexpectedly trying to check out "FETCH_HEAD". Not fetch head set.');
186 }
187 this.head = {ref: this.fetchHeadRef, newCommits: []};
188 } else if (this.branches[target]) {
189 this.head = this._cloneHead(this.branches[target], detached);
190 } else if (createBranch) {
191 this.head = this.branches[target] = {
192 branch: target,
193 ...this._cloneHead(this.head, detached),
194 };
195 } else {
196 throw Error(`Unexpected branch checked out: ${target}`);
197 }
198 }
199
200 /**
201 * Unwraps a refspec into the base and target ref names.

Callers 1

runGracefulMethod · 0.95

Calls 1

_cloneHeadMethod · 0.95

Tested by

no test coverage detected