Commit Graph

71 Commits

Author SHA1 Message Date
Tim Hockin 69eb59185a Env var handling should prefer old names
For back-compat, if we find both an old and new env var for the same
flag, prefer the old.  This matters because the docker image sets
GITSYNC_ROOT but some users still set GIT_SYNC_ROOT.
2024-12-12 15:35:26 -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
Tim Hockin 9782ee2cfb Add docs on symlink 2024-08-12 10:27:24 -07:00
VICIWUOHA af8126a4a0 fix slight typo in README 2024-06-24 23:11:48 +01: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
demoth 5425f59147
README.md - fix usage comments 2024-04-10 11:56:34 +02: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 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
Ofek Buchnik 12fd9ccb56
Update README.md
Fix in README from "chan ges" to "changes"
2023-07-19 23:45:59 +03:00
Tim Hockin 54333f453f Update README.md
Update README to be less "dev branch hacky hacky"
2023-07-18 09:58:03 -07:00
Tim Hockin 8981e7f5bb Document the / URL of the HTTP port 2023-07-16 12:10:40 -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 8ee0f7ef9a Update README and other docs 2023-05-16 16:10:50 -07:00
Tim Hockin c3a49e9d46 Get rid of "must not start with ." logic
It serves very little purpose and isn't even correct as-is.
2023-05-14 11:11:24 -07:00
Tim Hockin 7e6b429362 Make all env var names GITSYNC_FOO
Still support GIT_SYNC_FOO for compat.
2023-05-04 08:45:25 -07:00
Tim Hockin 707d527e03 Add a doc about changing from v3 to v4 2023-04-29 10:42:26 -07:00
Tim Hockin e84a4cb4fd Make --webhook-success-status=0 the same as -1 2023-04-29 10:40:53 -07:00
Tim Hockin f6678b98e8 Change the default depth to 1
For most users this is functionally equivalent and more efficient.  For
users who really need the full history, set this to 0.
2023-04-28 14:07:35 -07:00
Tim Hockin ee6664748f Total overhaul of sync loop
The previous (v3) sync loop betrays my lack of understanding about git.
It tried to codify my archaic mental model (e.g. --branch and --rev
being disting things) and was ultimately a patchwork of corner-cases
evolved over a few years.

This commit is less of a "diff" and more of a "rewrite".

The new logic is simpler and more efficient.  It does not `git clone`
ever.  It does not differentiate the first sync from subsequent syncs.
It uses `git fetch` to get the exact SHA and then makes a worktree from
that.

The new `--ref` flag replaces both `--rev` and `--branch`, though it
will use those if specified.  In fact, almost all of the e2e tests
passed without change - using --ref and --branch!

I will follow this commit up with more cleanups and e2es.
2023-04-21 17:25:25 -07:00
Tim Hockin 3ce1ec617d Update README on master to point to v3 2023-01-25 10:17:22 -08:00
Tim Hockin bda1f84614
Add --touch-file flag and use it in tests
This is mostly designed to make testing easier instead of sleep.
2022-10-30 17:01:55 -07:00
Tim Hockin c32a042213
Make --error-file allow abs paths
This also enforces th previously unenforced "must not start with a
period" rule.
2022-09-05 14:54:10 -07:00
Tim Hockin f78dc35bf2
Fix some of the manual help text 2022-09-03 10:37:39 -07:00
Kubernetes Prow Robot 0c0c6f007b
Merge pull request #618 from thockin/fix-env-var-names
Allow flags to have multiple env var names
2022-08-30 02:09:01 -07:00
Tim Hockin eb33e7cfcb --max-sync-failures -> --max-failures
Deprecate but retain the old flag and env.
2022-08-21 10:48:20 -07:00
Tim Hockin 8c6dfeab89 Allow flags to have multiple env var names
Anything but the 0th name is considered deprecated.
2022-08-20 17:33:56 -07:00
Tim Hockin 037af64d3f Add notes about volumes and lost+found 2022-07-29 14:20:41 -07:00
Tim Hockin c7186a43b5 Update README to latest
This is the liter `git-sync --man` output
2022-03-08 08:56:17 -08:00
Tim Hockin 7b32caee77 v4: use repo default branch instead of master 2021-11-01 23:05:48 -07:00
Kubernetes Prow Robot 83d9a44f4f
Merge pull request #431 from zhouhaibing089/flag-password-file
Add option to read password from file
2021-07-05 15:21:38 -07:00
Haibing Zhou 6076daf3c4 Add option to read password from file
A new flag `--password-file` is added. This allows git-sync to read
password from file and this is considered as safer than reading from
env or flag directly.

Few more checks are added as well:

1. `--password` and `--password-file` can't be specified at the same
time.
1. If `--username` is specified, then one of `--password` or
`--password-file` must be specified.
2021-07-05 14:34:03 -07:00
XinYang 78a1cffbd3
remove broken analytics links
Signed-off-by: XinYang <xinydev@gmail.com>
2021-07-03 23:51:53 +08:00
Tim Hockin 903d86dd66 Update README to spec UID/GID 2021-06-04 16:00:26 -07:00
Tim Hockin a3d9b673a8 Port #372 to v4 dev branch (from SpencerMalone)
Wanted to finally tackle #54, I sidestepped the problem of how to handle the volume of flags that might be required by instead specifying a sparsecheckout file.

The workflow as I've had has been...
- Do a local sparse checkout, add the files you want ignored (or included on if you did a cone pattern https://git-scm.com/docs/git-sparse-checkout#_cone_pattern_set)
- Grab your .git/info/sparecheckout file, and reserve it for later use with this new flag

It's not quite as easy as specifying it all from a CLI, but I think it's a reasonable first pass.

Here are some logs of it being run on https://github.com/SpencerMalone/logstash-output-prometheus:

```
test-repo % cat sparseconfig
!/*
!/*/
README.md
test-repo % docker run --rm -d \
    -v $(pwd)/git-data:/tmp/git \
    -v $(pwd):/test \
    docker.io/registry/git-sync:tag__linux_amd64  \
        --repo=https://github.com/SpencerMalone/logstash-output-prometheus.git \
        --branch=master \
        --sparse-checkout-file=/test/sparseconfig
41494548dd64caf0ff8f7b75e4d3a86014cfaefc40ff31b14ba19accf99aa82f
test-repo % ls git-data/db86200b1ab158ce9ad403d06de2301b15333601
README.md
```

As you can see, I ignored everything but the `README.md`, and sure enough only got that file in my final checkout.
2021-04-23 09:01:05 -07:00
Nan Yu 53f3fa17a0 Export the error details to an error file
The current git-sync process outputs the error information to standard
out, which is inaccessible from outside the container. Users have to
dump the logs using kubectl logs in order to check the error details in
the git-sync process. This commit exports the error details to a file,
which provides users the capability to check the errors directly from
other sidecar containers.

proposal: https://github.com/kubernetes/git-sync/issues/326
2021-04-21 16:42:28 -07:00
Tim Hockin 83b4dd21de Add --git-config flag
This allows arbitrary git configs to be passed in.  For example:

`git config --global http.postBuffer 1048576000`

`git config --global http.sslCAInfo /path/to/cert/file`

`git config --global http.sslVerify false`

This flag takes a comma-separated list of `key:val` pairs.  The key part
is passed to `git config` and must be a valid gitconfig section header
and variable name.  The val part can be either a quoted or unquoted
value.  For all values the following escape sequences are supported:
   * `\n` => [newline]
   * `\t` => [tab]
   * `\"` => `"`
   * `\,` => `,`
   * `\\` => `\`

Within unquoted values, commas MUST be escaped. Within quoted values,
commas MAY be escaped, but are not required to be.  Any other escape
sequence is an error.

Example:

`--git-config=foo.one:val1,foo.two:"quoted val",foo.three:12345`

This commit exposed a bug in runCommand() which modified its args when
they had an embedded space.
2021-03-15 09:20:02 -07:00
Haiyan Meng 0010dafe6d Add the `--root` flag into the Usage section 2020-11-17 18:44:35 -08:00
Tim Hockin 0e802450ee Don't allow --dest to start with a dot
BREAKING CHANGE

It's useful to reserve names that start with a dot.
2020-11-09 08:36:10 -08:00
Tim Hockin af2ae5b533 Make the --root flag required, no default
BREAKING CHANGE

The default of $HOME has caused problems for people playing with
git-sync, so this change makes it a required argument.
2020-11-09 08:30:29 -08:00
Tim Hockin fa0e8696e2 Change time-related flags to durations
Add '--period' to replace '--wait', which is now obsolete.

Add '--sync-timeout' to replace '--timeout', which is now obsolete.

Both of these new flags take a Go-style time string, rather than a bare
number. For example "1s" for 1 second or "1m" for one minute.

The old flags have been kept and will take precedence if specified.
2020-11-05 16:46:09 -08:00
Tim Hockin 20696689f3 Add help and manual flags, use pflag
THIS IS A BREAKING CHANGE

Switch flags implementation to use pflag.  This means that long flags
like `-username` must now use 2 dashes: `--username`.

The `-v` flag (verbose) used to accept `-v` or `--v`.  Now it only
accepts `-v.

The `--help` and `-h` flags are new.

The `--man` flag is new (print a man-page like help message).

Several glog flags which used to be exposed (e.g. --logtostderr) are no
longer exposed.  Logs always go to stderr.
2020-10-31 00:50:51 -07:00
Xiang Dai 7df021c9ff README: add buildx comment
Signed-off-by: Xiang Dai <long0dai@foxmail.com>
2020-10-28 16:44:00 +08:00
Kubernetes Prow Robot c72a880352
Merge pull request #294 from andres-lowrie/master
docs: add PAT option for `--password`
2020-10-11 10:48:47 -07:00
Andres Lowrie 3c79569bd7
docs: add PAT option for `--password`
This could help users that are not aware that github personal access tokens can be used as passwords. It's verbose could be helpful
2020-10-06 11:23:18 -05:00
Michael Grosser decb118c58 Fix line breaks in README 2020-10-06 15:04:38 +00:00
unknowingknow 26cd942b2a change to a command name with no args 2020-10-02 19:29:03 +09:00