Skip to content

Git detection fails if nx workspace is part of a mixed git repo or does not contain the .git folder #37

@bzolivereckle

Description

@bzolivereckle

Issue

the function isRepo tests for the existence of the .git folder. In case of mixed repositories the nx workspace might not contain the .git but its located within a git repository.

export function isRepo(): boolean {
  return fs.existsSync('.git');
}

a probably better aproach will be running the git command that returns true

git rev-parse --is-inside-work-tree

Suggestion for the solution:

import { execSync } from "child_process";

function isRepo(): boolean {
  try {
    execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
    return true;
  } catch (error) {
    return false;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions