diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-04-15 13:30:36 +0200 |
|---|---|---|
| committer | Johannes Schindelin <johannes.schindelin@gmx.de> | 2024-04-17 00:01:26 +0200 |
| commit | 8c9c051bef3db0fe267f3fb6a1dab293c5f23b38 (patch) | |
| tree | 2de8610d3fa204f0aa0bcb62d5a9a356ffd94b7a /setup.c | |
| parent | builtin/clone: abort when hardlinked source and target file differ (diff) | |
| download | git-8c9c051bef3db0fe267f3fb6a1dab293c5f23b38.tar.gz git-8c9c051bef3db0fe267f3fb6a1dab293c5f23b38.zip | |
setup.c: introduce `die_upon_dubious_ownership()`
Introduce a new function `die_upon_dubious_ownership()` that uses
`ensure_valid_ownership()` to verify whether a repositroy is safe for
use, and causes Git to die in case it is not.
This function will be used in a subsequent commit.
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Diffstat (limited to 'setup.c')
| -rw-r--r-- | setup.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -1165,6 +1165,27 @@ static int ensure_valid_ownership(const char *gitfile, return data.is_safe; } +void die_upon_dubious_ownership(const char *gitfile, const char *worktree, + const char *gitdir) +{ + struct strbuf report = STRBUF_INIT, quoted = STRBUF_INIT; + const char *path; + + if (ensure_valid_ownership(gitfile, worktree, gitdir, &report)) + return; + + strbuf_complete(&report, '\n'); + path = gitfile ? gitfile : gitdir; + sq_quote_buf_pretty("ed, path); + + die(_("detected dubious ownership in repository at '%s'\n" + "%s" + "To add an exception for this directory, call:\n" + "\n" + "\tgit config --global --add safe.directory %s"), + path, report.buf, quoted.buf); +} + static int allowed_bare_repo_cb(const char *key, const char *value, void *d) { enum allowed_bare_repo *allowed_bare_repo = d; |
