int err = 0, complete_refs_before_fetch = 1;
int submodule_progress;
int filter_submodules = 0;
- const char *template_dir;
- char *template_dir_dup = NULL;
+ int hash_algo;
struct transport_ls_refs_options transport_ls_refs_options =
TRANSPORT_LS_REFS_OPTIONS_INIT;
--- /dev/null
- /*
- * Compare the file mode and contents of two given files.
- *
- * If both files are actually symbolic links, the function returns 1 if the link
- * targets are identical or 0 if they are not.
- *
- * If any of the two files cannot be accessed or in case of read failures, this
- * function returns 0.
- *
- * If the file modes and contents are identical, the function returns 1,
- * otherwise it returns 0.
- */
- int do_files_match(const char *path1, const char *path2);
-
+#ifndef COPY_H
+#define COPY_H
+
+#define COPY_READ_ERROR (-2)
+#define COPY_WRITE_ERROR (-3)
+int copy_fd(int ifd, int ofd);
+int copy_file(const char *dst, const char *src, int mode);
+int copy_file_with_time(const char *dst, const char *src, int mode);
+
+#endif /* COPY_H */
-#include "cache.h"
+#include "git-compat-util.h"
+#include "advice.h"
+#include "gettext.h"
#include "hook.h"
+#include "path.h"
#include "run-command.h"
#include "config.h"
- #include "copy.h"
-
- static int identical_to_template_hook(const char *name, const char *path)
- {
- const char *env = getenv("GIT_CLONE_TEMPLATE_DIR");
- const char *template_dir = get_template_dir(env && *env ? env : NULL);
- struct strbuf template_path = STRBUF_INIT;
- int found_template_hook, ret;
-
- strbuf_addf(&template_path, "%s/hooks/%s", template_dir, name);
- found_template_hook = access(template_path.buf, X_OK) >= 0;
- #ifdef STRIP_EXTENSION
- if (!found_template_hook) {
- strbuf_addstr(&template_path, STRIP_EXTENSION);
- found_template_hook = access(template_path.buf, X_OK) >= 0;
- }
- #endif
- if (!found_template_hook)
- return 0;
-
- ret = do_files_match(template_path.buf, path);
-
- strbuf_release(&template_path);
- return ret;
- }
+#include "strbuf.h"
+#include "environment.h"
+#include "setup.h"
const char *find_hook(const char *name)
{
test_cmp expected actual
'
- test_expect_success 'fsck warning on symlink target with excessive length' '
- symlink_target=$(printf "pattern %032769d" 1 | git hash-object -w --stdin) &&
- test_when_finished "remove_object $symlink_target" &&
- tree=$(printf "120000 blob %s\t%s\n" $symlink_target symlink | git mktree) &&
- test_when_finished "remove_object $tree" &&
- cat >expected <<-EOF &&
- warning in blob $symlink_target: symlinkTargetLength: symlink target too long
- EOF
- git fsck --no-dangling >actual 2>&1 &&
- test_cmp expected actual
- '
-
- test_expect_success 'fsck warning on symlink target pointing inside git dir' '
- gitdir=$(printf ".git" | git hash-object -w --stdin) &&
- ntfs_gitdir=$(printf "GIT~1" | git hash-object -w --stdin) &&
- hfs_gitdir=$(printf ".${u200c}git" | git hash-object -w --stdin) &&
- inside_gitdir=$(printf "nested/.git/config" | git hash-object -w --stdin) &&
- benign_target=$(printf "legit/config" | git hash-object -w --stdin) &&
- tree=$(printf "120000 blob %s\t%s\n" \
- $benign_target benign_target \
- $gitdir gitdir \
- $hfs_gitdir hfs_gitdir \
- $inside_gitdir inside_gitdir \
- $ntfs_gitdir ntfs_gitdir |
- git mktree) &&
- for o in $gitdir $ntfs_gitdir $hfs_gitdir $inside_gitdir $benign_target $tree
- do
- test_when_finished "remove_object $o" || return 1
- done &&
- printf "warning in blob %s: symlinkPointsToGitDir: symlink target points to git dir\n" \
- $gitdir $hfs_gitdir $inside_gitdir $ntfs_gitdir |
- sort >expected &&
- git fsck --no-dangling >actual 2>&1 &&
- sort actual >actual.sorted &&
- test_cmp expected actual.sorted
- '
-
+test_expect_success 'fsck detects problems in worktree index' '
+ test_when_finished "git worktree remove -f wt" &&
+ git worktree add wt &&
+
+ echo "this will be removed to break the worktree index" >wt/file &&
+ git -C wt add file &&
+ blob=$(git -C wt rev-parse :file) &&
+ remove_object $blob &&
+
+ test_must_fail git fsck --name-objects >actual 2>&1 &&
+ cat >expect <<-EOF &&
+ missing blob $blob (.git/worktrees/wt/index:file)
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'fsck reports problems in main index without filename' '
+ test_when_finished "rm -f .git/index && git read-tree HEAD" &&
+ echo "this object will be removed to break the main index" >file &&
+ git add file &&
+ blob=$(git rev-parse :file) &&
+ remove_object $blob &&
+
+ test_must_fail git fsck --name-objects >actual 2>&1 &&
+ cat >expect <<-EOF &&
+ missing blob $blob (:file)
+ EOF
+ test_cmp expect actual
+'
+
test_done