Commit Graph

34 Commits

Author SHA1 Message Date
Sam Dowell 00e00f019f fix: gracefully handle nil err in Logger
This handles the case where a null error is passed into the Logger
without causing a null pointer dereference / segfault. There are
currently a couple places that invoke this function with a nil error and
were resulting in a segfault.
2025-06-16 10:04:58 -07:00
Tim Hockin 913a6be647 Bump go and golangci-lint versions, fix lint 2025-03-24 13:43:12 -07:00
justinsb bb22144d4f lint: fix remaining lint issues.
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") {
        ^
```
2023-07-29 16:41:23 -04:00
Tim Hockin a9b3f8965c
Replace all error %v with %w 2023-07-29 10:21:39 -07:00
Tim Hockin 08296a48b0
Make relative-path submodules work, via origin
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.
2023-07-10 10:46:34 -07:00
Tim Hockin 9318041657 Better logging around hooks
This also returns stderr distinct from stdout.
2023-05-24 10:52:21 -07:00
Tim Hockin d197740d85 Exercise the git "dubious ownership" path
To do this, we run the e2e test as a different user.  To do that, we
need git-sync to make sure that everything is group accessible.  To
clean up after the test, we need everything to be group writable.  To do
that, we add a new flag: `--group-write`.
2023-05-07 10:29:39 -07:00
Tim Hockin 64ed3bb5a7 Capture and simplify a git.Run() method 2023-05-04 17:42:08 -07:00
Tim Hockin 10af97f51d Move worktrees to .worktrees/*
This will make it easier to enumerate old worktrees and do better
cleanup.
2023-04-29 10:51:13 -07:00
Tim Hockin e84a4cb4fd Make --webhook-success-status=0 the same as -1 2023-04-29 10:40:53 -07:00
Tim Hockin 026c6814c8 Add execution time to pkg/cmd runs 2023-04-06 17:45:54 -07:00
Tommy Hyeonwoo Kim 664fb74867
fix typo 2023-02-21 19:47:26 +09:00
Tim Hockin f5057b7fa8
Log commands we run with original caller 2023-02-10 21:18:28 -08:00
Eng Zer Jun 91113aa314
refactor: move from io/ioutil to io and os packages
The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

[1]: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-11-04 20:34:57 +08:00
Tim Hockin f8a532d9df Pass the whole environment to exechooks 2022-05-16 18:14:09 -07:00
Tim Hockin 3ca8099d2d Use logger.WithName() for web/exechook
This makes logs easier to comprehend, since hooks are async.
2022-03-17 12:10:39 -07:00
Tim Hockin 76854fc806 Set $GITSYNC_HASH in exechook 2022-02-06 16:49:34 -08:00
Tim Hockin b752a5eedc Fix tests to set missing arg 2022-02-06 16:29:57 -08:00
Kubernetes Prow Robot 10fd8e662b
Merge pull request #476 from thockin/v4-double-register-hook-metric
Don't double-register the hook metric (v4)
2022-01-23 01:17:56 -08:00
Tim Hockin 2a611a72c0 Don't double-register the hook metric 2022-01-22 14:24:47 -08:00
Tim Hockin c143bfd31a Small cleanup on one-time x hooks 2022-01-19 11:48:50 -08:00
ChrisERo ad6a34abb5 refactor: corrected variable names and logs inside HookRunner.WaitForCompletion 2022-01-15 15:23:06 -05:00
ChrisERo 8827bf7489 refactor: imporved efficiency and code style
* changed sendCompletedOnceMessageIfApplicable so that it kills thread
  after executing
* moved logic for waiting on HookRunner into function defined in
  HookRunner itself
2022-01-14 13:41:59 -05:00
ChrisERo 0df6e005d3 refactor: fixed in-line documentation and added line-wraps where needed 2022-01-10 20:06:23 -05:00
ChrisERo 3b5ed549eb fix: addressed several concers raised by thockin
- Renamed [x]HookChannel to [x]hookChannel for consistency
- Made hookChannels buffered chanels of size 1
- Added clarifying documentation and renamed functions expalining how I was
    - ensuring that hooks execute at least once, assuming that main thread does not crash
    - make sure chanels are not written to more than once
2022-01-10 20:06:06 -05:00
ChrisERo 9e6348c3b5 fix: resolve issue number 463
Resolved original issue by introducing a boolean chanel by which exechook runner can communicate with main thread.
Then introduced and used webhook executed-at-least-once chanel and added documentation explaining sections of of code
only executed when git-sync pulls for first time.
2022-01-10 20:05:53 -05:00
Tim Hockin 4603f559f3 Replace glogr with funcr
No difference in flags.  Log output will now be JSON.

example:

{"logger":"","ts":"2021-11-24 11:19:46.340238","caller":{"file":"main.go","line":1031},"level":0,"msg":"cloning repo","origin":"https://github.com/thockin/git-sync","path":"/tmp/gt"}
2021-11-24 11:18:07 -08:00
Tim Hockin 0ea10cbbc2 Add one call depth to compensate for log pkg 2021-08-16 23:45:10 -07:00
Tim Hockin 0075df238c Make exechooks work like webhooks.
This deprecates the `--sync-hook-command` flag in favor of
`--exechook-command`, `--exechook-timeout`, and `--exechook-backoff`.
2021-08-16 23:21:20 -07:00
Tim Hockin 0222a95f29 Make sure all code files have headers 2021-05-27 08:46:00 -07:00
Tim Hockin 45b28530a7 Fix exit non-zero exit codes when running as pid1
(v4 branch)

Prior to this we would swallow the exit code and always exit(0).
2021-03-15 09:28:26 -07:00
Tim Hockin 95a1690e6f Fix 2 bugs in pid1
1) Was calling Wait() on the child process, but also calling Wait4,
which would race, causing an occasional error or panic.

2) In testing (1), I observed occasional hangs.  Tracing it down to a
SIGWINCH, which masked a SIGCHLD, causing it to hang.  Both seem fixed.

Added a manual test script.
2020-03-20 13:44:27 -07:00
Tim Hockin 2a42fba009 Handle running as pid 1
This detects when it is running as pid 1, and becomes an init process.
Specifically this means handling SIGCHLD and reaping processes
(otherwise they become zombies) and forwarding signals to "real"
process.

We fork and re-exec ourselves so that we only get *this* SIGCHLD for
orphaned processes (re-parented to 1) and not the real events from
running things like git or ssh.
2019-10-27 09:45:27 -07:00
Tim Hockin 70feeb5ae1 Use the go-build-template
Faster builds and versions from tags.  Also use alpine as a base image.  We
need alpine for other architectures...

Also change the --wait flag to take a float for sub-second waits.
2016-10-30 17:09:06 -07:00