Commit Graph

161 Commits

Author SHA1 Message Date
Tim Hockin 81c8b2f39e Clean up askpass_URL
* Tighten git e2e shim
  - exit on errors'
  - simpler
  - don't set XDG_CONFIG_HOME

* Reword help strings and logs
2022-07-03 11:25:47 -07:00
Tim Hockin 185074f250 Beef up askpass_url support
* Don't need to get the password at startup (it happens in the sync loop
  anyway)
* Add tests for bad password and flaky URL
2022-07-02 15:43:01 -07:00
Tim Hockin 0a5952af7f Clean up fail-count logging
Increment it before logging it!
2022-06-24 09:42:24 -07:00
Tim Hockin 812da0c43e Pass the whole environment to exechooks 2022-05-16 18:07:46 -07:00
Kubernetes Prow Robot dbbebf2e48
Merge pull request #499 from sed-i/feature/support_repo_change
Support repo change between invocations
2022-03-10 17:08:08 -08:00
sed-i 4ca7832b0f Do not pass global flags outside of main 2022-02-25 02:22:37 -05:00
sed-i 50f6327baf Replace "origin" literal with flRepo
Replaces the hard-coded literal "origin" with the --repo value.
This way cleanup takes place even if --repo value changes between
invocations.
2022-02-24 23:33:15 -05:00
Tim Hockin ad3955c0fa Add --git-gc flag to control GC on each sync
Values:
* "auto" - run `git gc --auto` (default, respects git gc.* configs)
* "always" - run `git gc`
* "aggressive" - run `git gc --aggressive` (may require a longer timeout)
* "off" - do not run `git gc` on each sync (good for --one-time use)
2022-02-23 16:23:55 -08:00
Tim Hockin 47404c921e Set some gc.* git config
In particular, this sets `gc.autoDetach` to "false".
2022-02-19 16:40:31 -08:00
Tim Hockin ff156800a0 Set repoReady even when there wasn't a 1st clone
E.g. if the repo is already present (after a restart).
2022-02-12 17:35:04 -08:00
Tim Hockin 32e0d53b33 Set $GITSYNC_HASH in exechook 2022-02-06 16:26:04 -08:00
Tim Hockin 76654434f2 Fix bug caused in previous PR
The .git to check is not the root/.git but the link/.git - tests pass
now.
2022-01-24 11:01:26 -08:00
Kubernetes Prow Robot 0ce336f03c
Merge pull request #477 from thockin/v3-link-abspath
Allow --dest to be an absolute path (v3)
2022-01-23 02:37:56 -08:00
Tim Hockin ce8c4d38e0 Allow --dest to be an absolute path
This means it might live outside of --root.
2022-01-22 23:26:36 -08:00
Tim Hockin fb895f2c12 Don't try to remove the root if it appears corrupt
The `--root` is often a volume and can't be removed.  Instead, remove
the contents of it.  Adjust tests to hit this.
2022-01-22 12:47:19 -08:00
Tim Hockin 89b0bd5448 Ensure web/exec hooks complete in --one-time
Also some small e2e cleanups.  This is a port from master branch.
2022-01-19 12:01:15 -08:00
Nan Yu ad7f801609 Expose the ssh diagnostic message
When git-sync fails to clone the git project, the ssh diagnostic message
is suppressed. It is sometimes helpful for debugging the cloning issue.
One example of the ssh dianostic message is
```
ssh: Could not resolve hostname ${REPO_HOST}: Name or service not known
```

This commit removes the `-q` flag from the ssh command to expose such
message.
2022-01-06 16:12:06 -08:00
Mac Chaffee 0f1ed5e8e6
Avoid writing to /etc/passwd unless needed (#461)
* Avoid writing to /etc/password unless needed

Signed-off-by: Mac Chaffee <me@macchaffee.com>

* Use user.LookupId to check /etc/passwd

Signed-off-by: Mac Chaffee <me@macchaffee.com>

* Remove unused variables

Signed-off-by: Mac Chaffee <me@macchaffee.com>
2021-12-23 09:22:37 -08:00
yedamo a7acf14da7 fix typo 2021-11-20 13:08:19 +08:00
and-1 cca5a5e917 Fix password-file flag declaration 2021-10-12 21:38:25 -07:00
Natalie Baker 2c3bb035f6 Use hash for branch when adding a new worktree 2021-10-04 16:55:32 -04:00
Tim Hockin 9835c219d0 Fix env var names 2021-08-17 08:26:59 -07:00
ugurkenar df69fab365 cmd,hook and logging package 2021-08-16 12:40:27 +03:00
Tim Hockin 2a81ea69f0 Add option to read passwd from file
This is a port of #431.

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.
2. If `--username` is specified, then one of `--password` or
`--password-file` must be specified.
2021-07-05 15:49:18 -07:00
barney-s 6baccb4c5d Check for rev to be present after a fetch
When we fetch expecting a rev/hash to be present, defensively check and fail gracefully so that a subsequent sync would get it.  Check for missing hash after a git fetch with shallow depth
2021-06-23 14:56:39 -04:00
barney-s fe9c059828 Cleanup worktree defensively
This is to avoid wedge cases where the worktree was created but this function error'd without cleaning the worktree.
Next timearound, the sync loop fails to create the worktree and bails out.

We observed a case where due to #412, the next sync loop failed with this error:
" Run(git worktree add /repo/root/rev-nnnn origin/develop): exit status 128: { stdout: \"Preparing worktree (detached HEAD nnnn)\\n\", stderr: \"fatal: '/repo/root/rev-nnnn' already exists\\n\" }"
2021-06-22 16:40:58 -04:00
Brian Kennedy edb3f08ec0 Improve error message for askpass.
When endpoint returns non-200 status, include the body in the error
message since it can contain useful information for debugging.  Also
defer closing the response body ReadCloser as this may have leaked in
the past.
2021-06-15 13:38:01 -07:00
Tim Hockin 4765eb5b14 Make sure all code files have headers 2021-05-27 08:45:36 -07:00
Tim Hockin ba20771195 Small error string cleanup 2021-05-26 17:02:54 -07:00
Nan Yu a00627d155 Grant read access for the error file to all users 2021-05-26 14:34:43 -07:00
Tim Hockin e9e682e25e Clean up global flRoot use 2021-05-21 17:10:57 -07:00
Nan Yu 59f8f6a8e1 Create the root directory if it doesn't exist
The `git clone` command will create the root directory if it doesn't
exist, but if `git clone` fails, the root directory needs to be present
so that we can write the error to a file under the directory.
2021-05-11 16:59:17 -07:00
Kubernetes Prow Robot a3affe9040
Merge pull request #372 from SpencerMalone/sparse-checkouts
Add support for sparse-checkout
2021-04-23 08:32:02 -07:00
Spencer Malone 07e552b506 Add support for sparse-checkout 2021-04-23 08:17:58 -07:00
Nan Yu 8ea449292b 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-09 11:00:52 -07:00
Tim Hockin d508f04bbe Move sync-hook to after symlink flip 2021-04-05 17:04:44 -07:00
Tim Hockin 11c2a1fd7b Fix exit non-zero exit codes when running as pid1
Prior to this we would swallow the exit code and always exit(0).
2021-03-15 09:30:46 -07:00
Kubernetes Prow Robot de2a216922
Merge pull request #341 from thockin/add-git-configs-flag-3.x
Add --git-config flag
2021-03-15 07:45:05 -07:00
Tim Hockin 770314995f Change the symlink targets to just the SHA
This allows users to call readlink() on the link and learn the current
checked out SHA.
2021-03-11 22:07:07 -08:00
Tim Hockin 45bba183ca 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-10 19:07:05 -08:00
Tim Hockin ffba2eb119 Allow octal and hex values for int flags
This is specifcally relevant to --change-permissions.
2021-01-06 13:49:02 -08:00
unknowingknow 26cd942b2a change to a command name with no args 2020-10-02 19:29:03 +09:00
unknowingknow e1c4717de6 add an option to run the command when the repository is updated 2020-10-02 19:28:25 +09:00
Tim Hockin 44e94a16b0 Fix webhook regression: allow -1 to ignore status 2020-09-25 11:17:56 -07:00
Kubernetes Prow Robot 66320a6b92
Merge pull request #243 from killuazhu/kyle-relax-wait
Relax wait between sync
2020-09-25 10:30:26 -07:00
Tim Hockin 4225d000e0 Clean up askpass function to take url as arg 2020-09-07 17:16:56 -07:00
Kubernetes Prow Robot ed57c29d83
Merge pull request #275 from thockin/7-askpass-metric
Add metric for askpass, noop sync != success
2020-09-07 17:11:42 -07:00
Tim Hockin 9cef5f8ced Improve flag input checking and errors 2020-09-05 10:30:25 -07:00
Kubernetes Prow Robot f67c13654e
Merge pull request #277 from thockin/9-better-logs
Better logs and errors
2020-09-05 10:27:40 -07:00
Kubernetes Prow Robot 9c56b25591
Merge pull request #276 from thockin/8-use-filepath
use filepath.Join, drop dep on path
2020-09-05 10:25:41 -07:00