# core/probes/vcs.probe.ts

> 45 lines of code and 6 definitions.

Tree: Bane's Lab Deploy
Language: typescript
Layer: operations
Canonical: https://banes-lab.com/anatomy/deploy#file-deploy-core-probes-vcs-probe-ts
Source text: https://banes-lab.com/source/deploy/core/probes/vcs.probe.ts.txt

Listed in [core/probes](https://banes-lab.com/api/source/deploy/core/probes.md), after [core/probes/system.probe.ts](https://banes-lab.com/source/deploy/core/probes/system.probe.ts.md).

## Definitions

- `query` (lexical_declaration, line 20)
- `describeCheckout` (lexical_declaration, line 34, exported)
- `branchOf` (lexical_declaration, line 26)
- `VCS_BINARY` (lexical_declaration, line 18)
- `head` (lexical_declaration, line 35, exported)
- `entries` (lexical_declaration, line 39, exported)

## Contained in

- [core/probes](https://banes-lab.com/anatomy/deploy/folder-deploy-core-probes.md)

## Uses

- [core/converters/failure.converter.ts](https://banes-lab.com/source/deploy/core/converters/failure.converter.ts.md)
- [core/converters/markdown.converter.ts](https://banes-lab.com/source/deploy/core/converters/markdown.converter.ts.md)

## Used by

- [core/reporters/deployment.reporter.ts](https://banes-lab.com/source/deploy/core/reporters/deployment.reporter.ts.md)

## Linked from

- [core/converters](https://banes-lab.com/anatomy/deploy/folder-deploy-core-converters.md)
- [core/probes](https://banes-lab.com/anatomy/deploy/folder-deploy-core-probes.md)
- [core/reporters](https://banes-lab.com/anatomy/deploy/folder-deploy-core-reporters.md)

## Source

```typescript
import {
    AUTHOR_LABEL,
    BRANCH_LABEL,
    COMMIT_LABEL,
    DIRTY_VALUE,
    MESSAGE_LABEL,
    NO_VCS,
    REASON_SEPARATOR,
    STATUS_LABEL,
} from "#configuration/strings/notification.strings";
import { COMMIT_MESSAGE_LIMIT, ELLIPSIS } from "#configuration/constants/deployment.constants";
import { bullet, code, lines } from "#core/converters/markdown.converter";
import { ROOT } from "@ssot/paths";
import { execFileSync } from "node:child_process";
import { messageOf } from "#core/converters/failure.converter";
import { truncate } from "#core/converters/text.converter";

const VCS_BINARY = "git";

const query = function query(args: readonly string[]): string {
    return execFileSync(VCS_BINARY, [...args], { cwd: ROOT, stdio: ["ignore", "pipe", "pipe"] })
        .toString()
        .trim();
};

const branchOf = function branchOf(): { branch: string } | { reason: string } {
    try {
        return { branch: query(["rev-parse", "--abbrev-ref", "HEAD"]) };
    } catch (error) {
        return { reason: messageOf(error) };
    }
};

export const describeCheckout = function describeCheckout(): string {
    const head = branchOf();
    if ("reason" in head) {
        return NO_VCS + REASON_SEPARATOR + head.reason;
    }
    const entries = [
        bullet(BRANCH_LABEL, code(head.branch)),
        bullet(COMMIT_LABEL, code(query(["rev-parse", "--short", "HEAD"]))),
        bullet(MESSAGE_LABEL, truncate(query(["log", "-1", "--pretty=%s"]), COMMIT_MESSAGE_LIMIT, ELLIPSIS)),
        bullet(AUTHOR_LABEL, query(["log", "-1", "--pretty=%an"])),
    ];
    if (query(["status", "--porcelain"]).length > 0) {
        entries.push(bullet(STATUS_LABEL, DIRTY_VALUE));
    }
    return lines(entries);
};
```
