Commit Graph

53 Commits

Author SHA1 Message Date
Yves Galante 28b8f36746
fix(auth): Fix ssh authentication
Signed-off-by: Yves Galante <yyvess@gmail.com>
2024-04-04 18:01:02 +02:00
Tim Hockin d5c61f7ad1 Try not to log credentials in repo URL
This extracts the username and password from the URL and replaces it
with the bare URL, using the usual credential mechanism for user/pass.
2023-12-14 10:12:26 -08:00
Tim Hockin 083d8dda85 Simplify inner loop: just fetch $ref
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
2023-12-08 18:25:00 -08:00
Tim Hockin ad92ba62c4 Make abspath Split return an abspath 2023-12-08 18:04:24 -08:00
Tim Hockin 9a806c09cb Bug: links are relative to linkdir, not rootdir 2023-12-08 18:04:24 -08:00
Tim Hockin 718a938cd4 Log worktree path 2023-12-08 18:04:24 -08:00
Tim Hockin a5cec7a036 Log less verbose flags in less verbose mode 2023-11-01 13:26:34 -07:00
Tim Hockin 83bd660494 Recover if wrong worktree HEAD 2023-10-14 15:55:00 -07:00
Tim Hockin 1a5daeaf43 Add e2e case for missing worktree after crash 2023-10-14 11:29:12 -07:00
Tim Hockin b69d0f3bac Logging: log syncCount and be less scary 2023-10-14 11:29:03 -07:00
Tim Hockin 8fa652dafa Break up main.go
Add new files for abspath, credential, and env functions.
2023-10-13 13:27:52 -07:00
Aleksandar Markovski ff51ca92dc fix: infinite bad loop caused by unexpected worktree directory removal 2023-10-13 13:20:54 -07:00
Tim Hockin 6426efe346 If --repo is not a URL, it's not an error 2023-10-13 12:35:13 -07:00
Tim Hockin fc5e065878 Only redact the URL password if it was provided 2023-10-13 12:35:13 -07:00
Tim Hockin 162e543e05 Add --credential flag to spec multiple user/pass
* New flag is a JSON-encoded struct.
* Add test case for multiple HTTP passwd.
2023-10-08 14:46:41 -07:00
Tim Hockin 4ccf0633fb Deprecate --ssh - it's not really needed
As long as a repo uses SSH transport (user@host:path or ssh://...), SSH
is active.  This is true for the main repo or submodules.
2023-09-27 13:32:15 -07:00
Tim Hockin 9bf6d7778d Set core.askPass config for better auth-fail error
Instead of "No such device or address", which is pretty obtuse, we now
get "Authentication failed".
2023-09-20 09:31:02 -07:00
Tim Hockin dbd0567882 Use correct keys on env parsing of alt names
These names are back-compat
2023-09-19 14:18:30 -07:00
Tim Hockin 29b291e9c2 Add support for multiple SSH keys
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.
2023-09-19 13:31:19 -07:00
Tim Hockin 310cbaea37 Add $GITSYNC_VERBOSE to set verbosity via env 2023-09-15 08:28:08 -07:00
Jiwon Park 8bb3467a24 fix: Fix backward compatibility of environment variables with bool type
Signed-off-by: Jiwon Park <bakjeeone@hotmail.com>
2023-08-31 07:39:54 +09: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
Kubernetes Prow Robot 41b71f5ce4
Merge pull request #788 from thockin/fix_git_option_parsing_goroutine_leak
Fix goroutine leak in git option parsing
2023-07-29 13:06:00 -07:00
Tim Hockin a9b3f8965c
Replace all error %v with %w 2023-07-29 10:21:39 -07:00
Tim Hockin d4f0c07bf1
Fix goroutine leak in git option parsing 2023-07-29 10:18:02 -07:00
Kubernetes Prow Robot f973ce04e0
Merge pull request #783 from justinsb/fix_lint_1
Lint fixes (part 1)
2023-07-29 10:16:00 -07:00
justinsb 07033fe697 Remove trailing newlines from errors
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)
2023-07-29 10:49:06 -04:00
justinsb 4aa9cd7487 Lint fixes (part 1)
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)
2023-07-29 10:44:16 -04:00
Karl Isenberg dd57eb0049
Handle errors from credential refresh
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.
2023-07-28 12:09:47 -07:00
Tim Hockin 8981e7f5bb Document the / URL of the HTTP port 2023-07-16 12:10:40 -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 c1afd4d578 Fix off-by-one in max-failures and docs 2023-06-18 10:59:29 -07:00
Tim Hockin 1894192b0f Run hooks at startup
This ensures we do not miss events.  E.g.

before:
    t0: hash changes to X
    t1: send webhook(X), waiting for response
    t2: hash changes to Y
    t3: queue next webhook(Y) but can't send because previous is not done
    t4: crash
    t5: restart
    t6: find repo at hash Y

    no webhook(Y) was sent.

after:
    t0: hash changes to X
    t1: send webhook(X), waiting for response
    t2: hash changes to Y
    t3: queue next webhook(Y) but can't send because previous is not done
    t4: crash
    t5: restart
    t6: find repo at hash Y
    t7: send webhook(Y), waiting for response
2023-05-29 14:50:24 -07:00
Tim Hockin a4afa2f438 Improve logging levels a bit 2023-05-26 09:04:55 -07:00
Tim Hockin 7797e5d0e3 Log actual flags rather than args+env 2023-05-24 10:52:39 -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 ed170912c9 Move main.go to root of repo
This allows `go install k8s.io/git-sync` which I like.
2023-05-22 08:40:24 -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
Tim Hockin 94ff3e8fae Fix non-master branches and tags
This plus the test should ensure no regressions.  Git makes it tricky to do
some things on a remote that you would think to do on a local repo.
`ls-remote` gives me the info I need with only one test for "HEAD" vs anything
else.
2016-10-28 17:02:25 +02:00
Tim Hockin 0adea90c44 Fix when a tag/rev moves
I know this used to work.  I must have broken it at some point. Manually
verified for HEAD and a real tag.

Also fix some logging so it is less chatty by default.

v2.0.2
2016-10-12 21:56:34 -07:00
Tim Hockin 4523b3a28d Better flag help, error on bad --dest, v2.0.1 2016-10-07 17:20:41 -07:00
Tim Hockin dd09cac833 Default dest to leaf of repo 2016-09-16 08:35:27 -07:00
Tim Hockin dd60fb0312 Clean up logging using glogr 2016-09-16 08:35:27 -07:00
Tim Hockin ff73d8e4f0 Overhaul git logic to sync only when needed
I wanted to understand it all so I ran a bunch of tests and found that it was
resyncing when not required any time the rev was not == HEAD.  Some
stackoverflow and git manpage spelunking produced this.  Nice side-effect is
tha the workdir is named after the githash instead of random.
2016-09-16 08:35:26 -07:00
Tim Hockin 7fcc902aa7 Print the git hash for any rev 2016-09-16 08:35:26 -07:00
Tim Hockin 75998b9237 clean up logging of git runs 2016-09-16 08:35:26 -07:00
Tim Hockin cd1f719e8b Overhaul runCommand()
Better args, logging.
2016-09-16 08:35:26 -07:00
Tim Hockin 344eca6507 Reorder args to make more sense 2016-09-16 08:35:26 -07:00
Tim Hockin 119465829f Minor log cleanup in prep for later changes 2016-09-16 08:35:26 -07:00
Tim Hockin 2d9dbf9fa6 clean up flag definitions 2016-09-16 08:35:26 -07:00