Commit Graph

71 Commits

Author SHA1 Message Date
Tylen Wells fcbb1d1603 update man 2025-07-01 16:51:21 -07:00
Tylen Wells 7d518656e4 add function to call hooks and implement --hooks-before-symlink 2025-07-01 16:34:51 -07:00
Tylen Wells 1e02613a51 implement --hooks-async 2025-07-01 16:28:52 -07:00
AlanZhang2002 21fce7f2a1 added separator after ref to remove git reset --soft ambiguity 2025-04-29 10:29:16 -07:00
Tim Hockin 913a6be647 Bump go and golangci-lint versions, fix lint 2025-03-24 13:43:12 -07:00
Tim Hockin cffb28d447 Set SSH verbosity based on git-sync -v value 2024-12-12 13:49:49 -08:00
Liam Wyllie 0e2e0f0adc Add support for GitHub app authentication
Signed-off-by: Liam Wyllie <risset@mailbox.org>
2024-09-25 11:51:39 -07:00
Sam Dowell ae22b20d07 fix: recover when there is unreleased lock file
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.
2024-08-12 10:55:47 -07:00
Tim Hockin 9782ee2cfb Add docs on symlink 2024-08-12 10:27:24 -07:00
Tim Hockin 189a690a5b Add -? to manual 2024-06-13 14:40:14 -07:00
Tim Hockin 28394608e8 Add the idea of "env-flags"
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.
2024-06-13 14:40:14 -07:00
Tim Hockin fbc717e620
Clean up flag-related messages 2024-06-09 10:54:19 -07:00
Tim Hockin b5b0558d58 Bump golangci-lint and fix lint 2024-06-09 00:57:47 -07:00
Tim Hockin b4dfc82490 Log the git version 2024-06-09 00:42:51 -07:00
Tim Hockin cd1d050a67 Log the binary version 2024-06-09 00:42:51 -07:00
Tim Hockin 4a4c8f8d11 Don't log hidden flags 2024-06-09 00:42:51 -07:00
Tim Hockin aa2ac24c25 Support -? as an alias for --help
Also print errors before and after usage, like pflag.
2024-06-08 14:10:38 -07:00
Tim Hockin f521da5548 Add e2e for ssh:// URLs 2024-04-04 16:40:32 -07:00
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