If a previous git invocation crashes, it is possible that an orphaned
lock file (e.g. shallow.lock) is left on the filesystem. This previously
caused git-sync to crash loop because the lock file is never deleted.
This change adds a check in sanityCheckRepo for the existence of a git
lock file. If the git lock file exists at this stage, then initRepo will
re-initialize the repository.
Env-flags are "flags" that can only be set by env var (see caveat below).
All of the real flags have a corresponding env-flag (kind of, but not
really). The real goal was to deprecate `--password` but keep the env
var as a documented interface.
This does that (though --password still works) and updates the usage and
manual.
This allows some future work to follow the pattern. We do not register
every CLI flag as an env-flag because the help text would be
duplicative. This probably wants a wrapper API that allows declaring of
abstract flags, with CLI, env, or both sources.
Caveat:
ACTUALLY, these still have a flag, but the flag is specially named and
hidden. This makes testing a little easier where passing flags is
handled well but env vars is not.
Old way:
- ls-remote $ref $ref^{} and parse
- compare to current
- if changed, fetch
- update worktree
New way:
- fetch $ref
- compare to current
- if change, update worktree
The --ssh-key-file flag can be specified more than once and the
GITSYNC_SSH_KEY_FILE env var will be parsed like PATH.
Also adds e2e coverage for wrong-key and for multiple keys.
These fix the issues identified by the k/k inspired linter
configuration that we will be adding:
```
pkg/pid1/pid1.go:72:14: ST1005: error strings should not end with punctuation or newlines (stylecheck)
return 0, fmt.Errorf("unhandled exit status: 0x%x\n", status)
^
pkg/pid1/pid1.go:86:21: ST1005: error strings should not end with punctuation or newlines (stylecheck)
return false, 0, fmt.Errorf("wait4(): %w\n", err)
^
main.go:480:34: Error return value of `pflag.CommandLine.MarkDeprecated` is not checked (errcheck)
pflag.CommandLine.MarkDeprecated("branch", "use --ref instead")
^
main.go:483:34: Error return value of `pflag.CommandLine.MarkDeprecated` is not checked (errcheck)
pflag.CommandLine.MarkDeprecated("change-permissions", "use --group-write instead")
^
main.go:486:34: Error return value of `pflag.CommandLine.MarkDeprecated` is not checked (errcheck)
pflag.CommandLine.MarkDeprecated("dest", "use --link instead")
^
main.go:1897:16: Error return value of `io.WriteString` is not checked (errcheck)
io.WriteString(h, s)
^
main.go:555:2: ifElseChain: rewrite if-else to switch statement (gocritic)
if *flDeprecatedBranch != "" && (*flDeprecatedRev == "" || *flDeprecatedRev == "HEAD") {
^
```
I believe we print a new line anyway from e.g. envInt, which calls fmt.Fprintln.
Found by staticcheck:
main.go:127:17: error strings should not end with punctuation or newlines (ST1005)
main.go:157:13: error strings should not end with punctuation or newlines (ST1005)
main.go:187:13: error strings should not end with punctuation or newlines (ST1005)
main.go:217:13: error strings should not end with punctuation or newlines (ST1005)
Fix a few misc linter issues:
main_test.go:750:7: Error return value is not checked (errcheck)
touch(dirPath)
^
main_test.go:759:7: Error return value is not checked (errcheck)
touch(filePath)
^
main_test.go:768:7: Error return value is not checked (errcheck)
touch(newfilePath)
^
main.go:2089:3: S1023: redundant `return` statement (gosimple)
return
^
main.go:1935:13: S1039: unnecessary use of fmt.Sprintf (gosimple)
sshCmd += fmt.Sprintf(" -o StrictHostKeyChecking=no")
^
main.go:1152:33: SA1016: os.Kill cannot be trapped (did you mean syscall.SIGTERM?) (staticcheck)
signal.Notify(c, os.Interrupt, os.Kill)
Previously, errors from askpass and credential storage were being
ignored, causing git clone/fetch to later error with hard-to-read
errors.
Now the error indicates the credential refresh as the problem, and
does not try to sync.
The "origin" remote is implicitly used as the basis for relative-paths
in submodules. It's very subtly documented, and I have no idea if there
are other places where it is used. It seems git really expects it to
exist, so let's just do that.