()
| 344 | } |
| 345 | |
| 346 | func changeToWorkingCopy() { |
| 347 | workingDir := cfg.LocalWorkingDir() |
| 348 | cwd, err := tools.Getwd() |
| 349 | if err != nil { |
| 350 | ExitWithError(errors.Wrap( |
| 351 | err, tr.Tr.Get("Could not determine current working directory"))) |
| 352 | } |
| 353 | cwd, err = tools.CanonicalizeSystemPath(cwd) |
| 354 | if err != nil { |
| 355 | ExitWithError(errors.Wrap( |
| 356 | err, tr.Tr.Get("Could not canonicalize current working directory"))) |
| 357 | } |
| 358 | |
| 359 | // If the current working directory is not within the repository's |
| 360 | // working directory, then let's change directories accordingly. This |
| 361 | // should only occur if GIT_WORK_TREE is set. |
| 362 | if !(strings.HasPrefix(cwd, workingDir) && (cwd == workingDir || (len(cwd) > len(workingDir) && cwd[len(workingDir)] == os.PathSeparator))) { |
| 363 | os.Chdir(workingDir) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | func canonicalizeEnvironment() { |
| 368 | vars := []string{"GIT_INDEX_FILE", "GIT_OBJECT_DIRECTORY", "GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR"} |
no test coverage detected