InferRepoRootAndSubpath infers the root of the Git repository and the subpath from the given path. Since the extraction stops at first .git directory it means that if a subpath in a github monorepo is deployed as a rill managed project it will prevent the subpath from being inferred. This means : -
(path string)
| 352 | // - user will need to explicitly set the subpath if they want to connect this to Github. |
| 353 | // - When finding matching projects it will only list the rill managed projects for that subpath. |
| 354 | func InferRepoRootAndSubpath(path string) (string, string, error) { |
| 355 | // check if is a git repository |
| 356 | repoRoot, err := InferGitRepoRoot(path) |
| 357 | if err != nil { |
| 358 | return "", "", err |
| 359 | } |
| 360 | |
| 361 | // infer subpath if it exists |
| 362 | subPath, err := filepath.Rel(repoRoot, path) |
| 363 | if err != nil { |
| 364 | // should never happen because repoRoot is detected from path |
| 365 | return "", "", err |
| 366 | } |
| 367 | if subPath == "." || subPath == "" { |
| 368 | // no subpath |
| 369 | return repoRoot, "", nil |
| 370 | } |
| 371 | // check if subpath is in .gitignore |
| 372 | ignored, err := isGitIgnored(repoRoot, subPath) |
| 373 | if err != nil { |
| 374 | return "", "", err |
| 375 | } |
| 376 | if ignored { |
| 377 | // if subpath is ignored this is not a valid git path |
| 378 | return "", "", ErrNotAGitRepository |
| 379 | } |
| 380 | return repoRoot, subPath, nil |
| 381 | } |
no test coverage detected