Merge branch 'ps/config-error' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 10 Mar 2016 19:13:38 +0000 (11:13 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Mar 2016 19:13:38 +0000 (11:13 -0800)
Many codepaths forget to check return value from git_config_set();
the function is made to die() to make sure we do not proceed when
setting a configuration variable failed.

* ps/config-error:
config: rename git_config_set_or_die to git_config_set
config: rename git_config_set to git_config_set_gently
compat: die when unable to set core.precomposeunicode
sequencer: die on config error when saving replay opts
init-db: die on config errors when initializing empty repo
clone: die on config error in cmd_clone
remote: die on config error when manipulating remotes
remote: die on config error when setting/adding branches
remote: die on config error when setting URL
submodule--helper: die on config error when cloning module
submodule: die on config error when linking modules
branch: die on config error when editing branch description
branch: die on config error when unsetting upstream
branch: report errors in tracking branch setup
config: introduce set_or_die wrappers

30 files changed:
Documentation/RelNotes/2.7.2.txt [new file with mode: 0644]
Documentation/git-clean.txt
Documentation/git-worktree.txt
Documentation/git.txt
GIT-VERSION-GEN
RelNotes
builtin/blame.c
builtin/grep.c
builtin/rm.c
builtin/stripspace.c
cache-tree.c
cache.h
contrib/completion/git-completion.bash
git-cvsserver.perl
mergetools/vimdiff
read-cache.c
remote-curl.c
remote.c
setup.c
t/t1501-work-tree.sh [new file with mode: 0755]
t/t1501-worktree.sh [deleted file]
t/t1509-root-work-tree.sh [new file with mode: 0755]
t/t1509-root-worktree.sh [deleted file]
t/t5533-push-cas.sh
t/t6023-merge-file.sh
t/t7409-submodule-detached-work-tree.sh [new file with mode: 0755]
t/t7409-submodule-detached-worktree.sh [deleted file]
t/test-lib.sh
worktree.c
xdiff/xmerge.c
diff --git a/Documentation/RelNotes/2.7.2.txt b/Documentation/RelNotes/2.7.2.txt
new file mode 100644 (file)
index 0000000..4feef76
--- /dev/null
@@ -0,0 +1,41 @@
+Git v2.7.2 Release Notes
+========================
+
+Fixes since v2.7.1
+------------------
+
+ * The low-level merge machinery has been taught to use CRLF line
+   termination when inserting conflict markers to merged contents that
+   are themselves CRLF line-terminated.
+
+ * "git worktree" had a broken code that attempted to auto-fix
+   possible inconsistency that results from end-users moving a
+   worktree to different places without telling Git (the original
+   repository needs to maintain backpointers to its worktrees, but
+   "mv" run by end-users who are not familiar with that fact will
+   obviously not adjust them), which actually made things worse
+   when triggered.
+
+ * "git push --force-with-lease" has been taught to report if the push
+   needed to force (or fast-forwarded).
+
+ * The emulated "yes" command used in our test scripts has been
+   tweaked not to spend too much time generating unnecessary output
+   that is not used, to help those who test on Windows where it would
+   not stop until it fills the pipe buffer due to lack of SIGPIPE.
+
+ * The vimdiff backend for "git mergetool" has been tweaked to arrange
+   and number buffers in the order that would match the expectation of
+   majority of people who read left to right, then top down and assign
+   buffers 1 2 3 4 "mentally" to local base remote merge windows based
+   on that order.
+
+ * The documentation for "git clean" has been corrected; it mentioned
+   that .git/modules/* are removed by giving two "-f", which has never
+   been the case.
+
+ * Paths that have been told the index about with "add -N" are not
+   quite yet in the index, but a few commands behaved as if they
+   already are in a harmful way.
+
+Also includes tiny documentation and test updates.
index 641681f61ad360fcfd5aa98f81a9e3d49c44c8a7..51a7e26a8ec178e7e9fd0b78c00bb7ce518cd049 100644 (file)
@@ -37,9 +37,7 @@ OPTIONS
        to false, 'git clean' will refuse to delete files or directories
        unless given -f, -n or -i. Git will refuse to delete directories
        with .git sub directory or file unless a second -f
-       is given. This affects also git submodules where the storage area
-       of the removed submodule under .git/modules/ is not removed until
-       -f is given twice.
+       is given.
 
 -i::
 --interactive::
index 5b9ad0429c84d2f11b0569f6d979858c833b3768..62c76c1c8945512009c6d0ca1179cf71ec50d04e 100644 (file)
@@ -32,11 +32,9 @@ The working tree's administrative files in the repository (see
 `git worktree prune` in the main or any linked working tree to
 clean up any stale administrative files.
 
-If you move a linked working tree to another file system, or
-within a file system that does not support hard links, you need to run
-at least one git command inside the linked working tree
-(e.g. `git status`) in order to update its administrative files in the
-repository so that they do not get automatically pruned.
+If you move a linked working tree, you need to manually update the
+administrative files so that they do not get pruned automatically. See
+section "DETAILS" for more information.
 
 If a linked working tree is stored on a portable device or network share
 which is not always mounted, you can prevent its administrative files from
@@ -137,6 +135,13 @@ thumb is do not make any assumption about whether a path belongs to
 $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something
 inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path.
 
+If you move a linked working tree, you need to update the 'gitdir' file
+in the entry's directory. For example, if a linked working tree is moved
+to `/newpath/test-next` and its `.git` file points to
+`/path/main/.git/worktrees/test-next`, then update
+`/path/main/.git/worktrees/test-next/gitdir` to reference `/newpath/test-next`
+instead.
+
 To prevent a $GIT_DIR/worktrees entry from being pruned (which
 can be useful in some situations, such as when the
 entry's working tree is stored on a portable device), add a file named
index d987ad20c90a05932733c09812324c3d176ebbbe..68a71b46c9c5706f76e73f55f6767d9f1ba07ce4 100644 (file)
@@ -43,9 +43,10 @@ unreleased) version of Git, that is available from the 'master'
 branch of the `git.git` repository.
 Documentation for older releases are available here:
 
-* link:v2.7.1/git.html[documentation for release 2.7.1]
+* link:v2.7.2/git.html[documentation for release 2.7.2]
 
 * release notes for
+  link:RelNotes/2.7.2.txt[2.7.2],
   link:RelNotes/2.7.1.txt[2.7.1],
   link:RelNotes/2.7.0.txt[2.7].
 
index 330b339d1cac1af441b16e35dcdefa660da1f683..d7ab24e35617a456f1998a141f7e620eca1de431 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v2.7.1
+DEF_VER=v2.7.2
 
 LF='
 '
index 213c0d0850d1d2d2e8fe85860a49810f23bb150a..64e8170aa2353dccbd67ef8767299f22fb765a8e 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/2.7.1.txt
\ No newline at end of file
+Documentation/RelNotes/2.7.2.txt
\ No newline at end of file
index 1df13cf7f4b501ed82dcbffdf4620706591a245e..5265f79edc907de356dea2ece4d1645210b7aad4 100644 (file)
@@ -2392,11 +2392,6 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
        ce->ce_mode = create_ce_mode(mode);
        add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
 
-       /*
-        * We are not going to write this out, so this does not matter
-        * right now, but someday we might optimize diff-index --cached
-        * with cache-tree information.
-        */
        cache_tree_invalidate_path(&the_index, path);
 
        return commit;
index 4229cae390ddddcc74f3506dc892ed02b45d7eae..3ba35ecf935f9462d8bb4340837f57e0e7219d05 100644 (file)
@@ -375,7 +375,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
 
        for (nr = 0; nr < active_nr; nr++) {
                const struct cache_entry *ce = active_cache[nr];
-               if (!S_ISREG(ce->ce_mode))
+               if (!S_ISREG(ce->ce_mode) || ce_intent_to_add(ce))
                        continue;
                if (!ce_path_match(ce, pathspec, NULL))
                        continue;
index 80b972f92fde3201bdf1cb8bd74c2b4ff53fa5ae..8829b09d0ba5d49edbad5f37f8246123dad3fd5f 100644 (file)
@@ -211,7 +211,7 @@ static int check_local_mod(unsigned char *head, int index_only)
                 * "intent to add" entry.
                 */
                if (local_changes && staged_changes) {
-                       if (!index_only || !(ce->ce_flags & CE_INTENT_TO_ADD))
+                       if (!index_only || !ce_intent_to_add(ce))
                                string_list_append(&files_staged, name);
                }
                else if (!index_only) {
index 7ff8434f7c3cf71dbd77cbf868d5dc56dd943fdb..15e716ef4322bb53428685c349aa489ed84a6dda 100644 (file)
@@ -35,7 +35,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
                            N_("skip and remove all lines starting with comment character"),
                            STRIP_COMMENTS),
                OPT_CMDMODE('c', "comment-lines", &mode,
-                           N_("prepend comment character and blank to each line"),
+                           N_("prepend comment character and space to each line"),
                            COMMENT_LINES),
                OPT_END()
        };
index a59e6f1e1fcfb65bd2fe9cdba0db60d6d87e7d96..20ee7b52df0c33d4473a198270705dffead01cdc 100644 (file)
@@ -377,7 +377,7 @@ static int update_one(struct cache_tree *it,
                 * they are not part of generated trees. Invalidate up
                 * to root to force cache-tree users to read elsewhere.
                 */
-               if (ce->ce_flags & CE_INTENT_TO_ADD) {
+               if (ce_intent_to_add(ce)) {
                        to_invalidate = 1;
                        continue;
                }
diff --git a/cache.h b/cache.h
index dd39270f93f15274f14477eeef405d63d82df30e..e2e64d188efdcfef25a5a9523b7324166a8863ca 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -259,6 +259,7 @@ static inline unsigned create_ce_flags(unsigned stage)
 #define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
 #define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
 #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
+#define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
 
 #define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644)
 static inline unsigned int create_ce_mode(unsigned int mode)
index 63f5c046a2c7058692657ffa4e97f20367bafedc..00d729996fab5be89696bf4841205d45c49c7794 100644 (file)
@@ -2413,8 +2413,8 @@ _git_stash ()
                show,--*|branch,--*)
                        ;;
                branch,*)
-                 if [ $cword -eq 3 ]; then
-                       __gitcomp_nl "$(__git_refs)";
+                       if [ $cword -eq 3 ]; then
+                               __gitcomp_nl "$(__git_refs)";
                        else
                                __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
                                                | sed -n -e 's/:.*//p')"
index 95e69b19a70ba63f2055d6a2ec3f9af0092a0832..02c0445be1057619e01e56bd6792f78fc011dc42 100755 (executable)
@@ -2664,7 +2664,7 @@ sub argsfromdir
     #   co  # Obtain list directly.
     #   remove # HERE: TEST: MAYBE client does the recursion for us,
     #          # since it only makes sense to remove stuff already in
-    #          # the sandobx?
+    #          # the sandbox?
     #   ci # HERE: Similar to remove...
     #      # Don't try to implement the confusing/weird
     #      # ci -r bug er.."feature".
index 1ddfbfcd782d3b8d0e479cb0c5e29abce86e63c9..74ea6d54793f62188cd88e93f1adfe74c5957dda 100644 (file)
@@ -9,8 +9,8 @@ merge_cmd () {
        gvimdiff|vimdiff)
                if $base_present
                then
-                       "$merge_tool_path" -f -d -c 'wincmd J' \
-                               "$MERGED" "$LOCAL" "$BASE" "$REMOTE"
+                       "$merge_tool_path" -f -d -c '4wincmd w | wincmd J' \
+                               "$LOCAL" "$BASE" "$REMOTE" "$MERGED"
                else
                        "$merge_tool_path" -f -d -c 'wincmd l' \
                                "$LOCAL" "$MERGED" "$REMOTE"
index 84616c8e219bf3cf902643a8da62a2060d335c36..5be7cd1dbf50c850ee5e02dcfde69d7611c181b5 100644 (file)
@@ -327,7 +327,7 @@ int ie_match_stat(const struct index_state *istate,
         * by definition never matches what is in the work tree until it
         * actually gets added.
         */
-       if (ce->ce_flags & CE_INTENT_TO_ADD)
+       if (ce_intent_to_add(ce))
                return DATA_CHANGED | TYPE_CHANGED | MODE_CHANGED;
 
        changed = ce_match_stat_basic(ce, st);
@@ -1237,7 +1237,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
 
                        if (cache_errno == ENOENT)
                                fmt = deleted_fmt;
-                       else if (ce->ce_flags & CE_INTENT_TO_ADD)
+                       else if (ce_intent_to_add(ce))
                                fmt = added_fmt; /* must be before other checks */
                        else if (changed & TYPE_CHANGED)
                                fmt = typechange_fmt;
index f404faf0f4b9ec298ccbae34fae0c79283884d26..e114f24448eae40a49acedcb85a0443d3b6ecba2 100644 (file)
@@ -439,8 +439,20 @@ static int run_slot(struct active_request_slot *slot,
        err = run_one_slot(slot, results);
 
        if (err != HTTP_OK && err != HTTP_REAUTH) {
-               error("RPC failed; result=%d, HTTP code = %ld",
-                     results->curl_result, results->http_code);
+               struct strbuf msg = STRBUF_INIT;
+               if (results->http_code && results->http_code != 200)
+                       strbuf_addf(&msg, "HTTP %ld", results->http_code);
+               if (results->curl_result != CURLE_OK) {
+                       if (msg.len)
+                               strbuf_addch(&msg, ' ');
+                       strbuf_addf(&msg, "curl %d", results->curl_result);
+                       if (curl_errorstr[0]) {
+                               strbuf_addch(&msg, ' ');
+                               strbuf_addstr(&msg, curl_errorstr);
+                       }
+               }
+               error("RPC failed; %s", msg.buf);
+               strbuf_release(&msg);
        }
 
        return err;
index 9d34b5a5dafa217e2ce9cb1b7e9a4ab74908f7af..3ceac07620cef06810c8f92adec735cc5baef832 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -1545,11 +1545,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
                }
 
                /*
-                * Bypass the usual "must fast-forward" check but
-                * replace it with a weaker "the old value must be
-                * this value we observed".  If the remote ref has
-                * moved and is now different from what we expect,
-                * reject any push.
+                * If the remote ref has moved and is now different
+                * from what we expect, reject any push.
                 *
                 * It also is an error if the user told us to check
                 * with the remote-tracking branch to find the value
@@ -1560,10 +1557,14 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
                        if (ref->expect_old_no_trackback ||
                            oidcmp(&ref->old_oid, &ref->old_oid_expect))
                                reject_reason = REF_STATUS_REJECT_STALE;
+                       else
+                               /* If the ref isn't stale then force the update. */
+                               force_ref_update = 1;
                }
 
                /*
-                * The usual "must fast-forward" rules.
+                * If the update isn't already rejected then check
+                * the usual "must fast-forward" rules.
                 *
                 * Decide whether an individual refspec A:B can be
                 * pushed.  The push will succeed if any of the
@@ -1582,7 +1583,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
                 *     passing the --force argument
                 */
 
-               else if (!ref->deletion && !is_null_oid(&ref->old_oid)) {
+               if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
                        if (starts_with(ref->name, "refs/tags/"))
                                reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
                        else if (!has_object_file(&ref->old_oid))
diff --git a/setup.c b/setup.c
index 2c4b22c8456733a3ab2848fff81630589139c671..0deb02238ba426144e0b7b077c9f2ad5c7993d23 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -451,17 +451,6 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
        return ret;
 }
 
-static void update_linked_gitdir(const char *gitfile, const char *gitdir)
-{
-       struct strbuf path = STRBUF_INIT;
-       struct stat st;
-
-       strbuf_addf(&path, "%s/gitdir", gitdir);
-       if (stat(path.buf, &st) || st.st_mtime + 24 * 3600 < time(NULL))
-               write_file(path.buf, "%s", gitfile);
-       strbuf_release(&path);
-}
-
 /*
  * Try to read the location of the git directory from the .git file,
  * return path to git directory if found.
@@ -531,7 +520,6 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
                error_code = READ_GITFILE_ERR_NOT_A_REPO;
                goto cleanup_return;
        }
-       update_linked_gitdir(path, dir);
        path = real_path(dir);
 
 cleanup_return:
diff --git a/t/t1501-work-tree.sh b/t/t1501-work-tree.sh
new file mode 100755 (executable)
index 0000000..cc5b870
--- /dev/null
@@ -0,0 +1,426 @@
+#!/bin/sh
+
+test_description='test separate work tree'
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       EMPTY_TREE=$(git write-tree) &&
+       EMPTY_BLOB=$(git hash-object -t blob --stdin </dev/null) &&
+       CHANGED_BLOB=$(echo changed | git hash-object -t blob --stdin) &&
+       EMPTY_BLOB7=$(echo $EMPTY_BLOB | sed "s/\(.......\).*/\1/") &&
+       CHANGED_BLOB7=$(echo $CHANGED_BLOB | sed "s/\(.......\).*/\1/") &&
+
+       mkdir -p work/sub/dir &&
+       mkdir -p work2 &&
+       mv .git repo.git
+'
+
+test_expect_success 'setup: helper for testing rev-parse' '
+       test_rev_parse() {
+               echo $1 >expected.bare &&
+               echo $2 >expected.inside-git &&
+               echo $3 >expected.inside-worktree &&
+               if test $# -ge 4
+               then
+                       echo $4 >expected.prefix
+               fi &&
+
+               git rev-parse --is-bare-repository >actual.bare &&
+               git rev-parse --is-inside-git-dir >actual.inside-git &&
+               git rev-parse --is-inside-work-tree >actual.inside-worktree &&
+               if test $# -ge 4
+               then
+                       git rev-parse --show-prefix >actual.prefix
+               fi &&
+
+               test_cmp expected.bare actual.bare &&
+               test_cmp expected.inside-git actual.inside-git &&
+               test_cmp expected.inside-worktree actual.inside-worktree &&
+               if test $# -ge 4
+               then
+                       # rev-parse --show-prefix should output
+                       # a single newline when at the top of the work tree,
+                       # but we test for that separately.
+                       test -z "$4" && ! test -s actual.prefix ||
+                       test_cmp expected.prefix actual.prefix
+               fi
+       }
+'
+
+test_expect_success 'setup: core.worktree = relative path' '
+       sane_unset GIT_WORK_TREE &&
+       GIT_DIR=repo.git &&
+       GIT_CONFIG="$(pwd)"/$GIT_DIR/config &&
+       export GIT_DIR GIT_CONFIG &&
+       git config core.worktree ../work
+'
+
+test_expect_success 'outside' '
+       test_rev_parse false false false
+'
+
+test_expect_success 'inside work tree' '
+       (
+               cd work &&
+               GIT_DIR=../repo.git &&
+               GIT_CONFIG="$(pwd)"/$GIT_DIR/config &&
+               test_rev_parse false false true ""
+       )
+'
+
+test_expect_success 'empty prefix is actually written out' '
+       echo >expected &&
+       (
+               cd work &&
+               GIT_DIR=../repo.git &&
+               GIT_CONFIG="$(pwd)"/$GIT_DIR/config &&
+               git rev-parse --show-prefix >../actual
+       ) &&
+       test_cmp expected actual
+'
+
+test_expect_success 'subdir of work tree' '
+       (
+               cd work/sub/dir &&
+               GIT_DIR=../../../repo.git &&
+               GIT_CONFIG="$(pwd)"/$GIT_DIR/config &&
+               test_rev_parse false false true sub/dir/
+       )
+'
+
+test_expect_success 'setup: core.worktree = absolute path' '
+       sane_unset GIT_WORK_TREE &&
+       GIT_DIR=$(pwd)/repo.git &&
+       GIT_CONFIG=$GIT_DIR/config &&
+       export GIT_DIR GIT_CONFIG &&
+       git config core.worktree "$(pwd)/work"
+'
+
+test_expect_success 'outside' '
+       test_rev_parse false false false &&
+       (
+               cd work2 &&
+               test_rev_parse false false false
+       )
+'
+
+test_expect_success 'inside work tree' '
+       (
+               cd work &&
+               test_rev_parse false false true ""
+       )
+'
+
+test_expect_success 'subdir of work tree' '
+       (
+               cd work/sub/dir &&
+               test_rev_parse false false true sub/dir/
+       )
+'
+
+test_expect_success 'setup: GIT_WORK_TREE=relative (override core.worktree)' '
+       GIT_DIR=$(pwd)/repo.git &&
+       GIT_CONFIG=$GIT_DIR/config &&
+       git config core.worktree non-existent &&
+       GIT_WORK_TREE=work &&
+       export GIT_DIR GIT_CONFIG GIT_WORK_TREE
+'
+
+test_expect_success 'outside' '
+       test_rev_parse false false false &&
+       (
+               cd work2 &&
+               test_rev_parse false false false
+       )
+'
+
+test_expect_success 'inside work tree' '
+       (
+               cd work &&
+               GIT_WORK_TREE=. &&
+               test_rev_parse false false true ""
+       )
+'
+
+test_expect_success 'subdir of work tree' '
+       (
+               cd work/sub/dir &&
+               GIT_WORK_TREE=../.. &&
+               test_rev_parse false false true sub/dir/
+       )
+'
+
+test_expect_success 'setup: GIT_WORK_TREE=absolute, below git dir' '
+       mv work repo.git/work &&
+       mv work2 repo.git/work2 &&
+       GIT_DIR=$(pwd)/repo.git &&
+       GIT_CONFIG=$GIT_DIR/config &&
+       GIT_WORK_TREE=$(pwd)/repo.git/work &&
+       export GIT_DIR GIT_CONFIG GIT_WORK_TREE
+'
+
+test_expect_success 'outside' '
+       echo outside &&
+       test_rev_parse false false false
+'
+
+test_expect_success 'in repo.git' '
+       (
+               cd repo.git &&
+               test_rev_parse false true false
+       ) &&
+       (
+               cd repo.git/objects &&
+               test_rev_parse false true false
+       ) &&
+       (
+               cd repo.git/work2 &&
+               test_rev_parse false true false
+       )
+'
+
+test_expect_success 'inside work tree' '
+       (
+               cd repo.git/work &&
+               test_rev_parse false true true ""
+       )
+'
+
+test_expect_success 'subdir of work tree' '
+       (
+               cd repo.git/work/sub/dir &&
+               test_rev_parse false true true sub/dir/
+       )
+'
+
+test_expect_success 'find work tree from repo' '
+       echo sub/dir/untracked >expected &&
+       cat <<-\EOF >repo.git/work/.gitignore &&
+       expected.*
+       actual.*
+       .gitignore
+       EOF
+       >repo.git/work/sub/dir/untracked &&
+       (
+               cd repo.git &&
+               git ls-files --others --exclude-standard >../actual
+       ) &&
+       test_cmp expected actual
+'
+
+test_expect_success 'find work tree from work tree' '
+       echo sub/dir/tracked >expected &&
+       >repo.git/work/sub/dir/tracked &&
+       (
+               cd repo.git/work/sub/dir &&
+               git --git-dir=../../.. add tracked
+       ) &&
+       (
+               cd repo.git &&
+               git ls-files >../actual
+       ) &&
+       test_cmp expected actual
+'
+
+test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
+       (
+               cd repo.git/work/sub/dir &&
+               GIT_DIR=../../.. &&
+               GIT_WORK_TREE=../.. &&
+               GIT_PAGER= &&
+               export GIT_DIR GIT_WORK_TREE GIT_PAGER &&
+
+               git diff --exit-code tracked &&
+               echo changed >tracked &&
+               test_must_fail git diff --exit-code tracked
+       )
+'
+
+test_expect_success 'diff-index respects work tree under .git dir' '
+       cat >diff-index-cached.expected <<-EOF &&
+       :000000 100644 $_z40 $EMPTY_BLOB A      sub/dir/tracked
+       EOF
+       cat >diff-index.expected <<-EOF &&
+       :000000 100644 $_z40 $_z40 A    sub/dir/tracked
+       EOF
+
+       (
+               GIT_DIR=repo.git &&
+               GIT_WORK_TREE=repo.git/work &&
+               export GIT_DIR GIT_WORK_TREE &&
+               git diff-index $EMPTY_TREE >diff-index.actual &&
+               git diff-index --cached $EMPTY_TREE >diff-index-cached.actual
+       ) &&
+       test_cmp diff-index.expected diff-index.actual &&
+       test_cmp diff-index-cached.expected diff-index-cached.actual
+'
+
+test_expect_success 'diff-files respects work tree under .git dir' '
+       cat >diff-files.expected <<-EOF &&
+       :100644 100644 $EMPTY_BLOB $_z40 M      sub/dir/tracked
+       EOF
+
+       (
+               GIT_DIR=repo.git &&
+               GIT_WORK_TREE=repo.git/work &&
+               export GIT_DIR GIT_WORK_TREE &&
+               git diff-files >diff-files.actual
+       ) &&
+       test_cmp diff-files.expected diff-files.actual
+'
+
+test_expect_success 'git diff respects work tree under .git dir' '
+       cat >diff-TREE.expected <<-EOF &&
+       diff --git a/sub/dir/tracked b/sub/dir/tracked
+       new file mode 100644
+       index 0000000..$CHANGED_BLOB7
+       --- /dev/null
+       +++ b/sub/dir/tracked
+       @@ -0,0 +1 @@
+       +changed
+       EOF
+       cat >diff-TREE-cached.expected <<-EOF &&
+       diff --git a/sub/dir/tracked b/sub/dir/tracked
+       new file mode 100644
+       index 0000000..$EMPTY_BLOB7
+       EOF
+       cat >diff-FILES.expected <<-EOF &&
+       diff --git a/sub/dir/tracked b/sub/dir/tracked
+       index $EMPTY_BLOB7..$CHANGED_BLOB7 100644
+       --- a/sub/dir/tracked
+       +++ b/sub/dir/tracked
+       @@ -0,0 +1 @@
+       +changed
+       EOF
+
+       (
+               GIT_DIR=repo.git &&
+               GIT_WORK_TREE=repo.git/work &&
+               export GIT_DIR GIT_WORK_TREE &&
+               git diff $EMPTY_TREE >diff-TREE.actual &&
+               git diff --cached $EMPTY_TREE >diff-TREE-cached.actual &&
+               git diff >diff-FILES.actual
+       ) &&
+       test_cmp diff-TREE.expected diff-TREE.actual &&
+       test_cmp diff-TREE-cached.expected diff-TREE-cached.actual &&
+       test_cmp diff-FILES.expected diff-FILES.actual
+'
+
+test_expect_success 'git grep' '
+       echo dir/tracked >expected.grep &&
+       (
+               cd repo.git/work/sub &&
+               GIT_DIR=../.. &&
+               GIT_WORK_TREE=.. &&
+               export GIT_DIR GIT_WORK_TREE &&
+               git grep -l changed >../../../actual.grep
+       ) &&
+       test_cmp expected.grep actual.grep
+'
+
+test_expect_success 'git commit' '
+       (
+               cd repo.git &&
+               GIT_DIR=. GIT_WORK_TREE=work git commit -a -m done
+       )
+'
+
+test_expect_success 'absolute pathspec should fail gracefully' '
+       (
+               cd repo.git &&
+               test_might_fail git config --unset core.worktree &&
+               test_must_fail git log HEAD -- /home
+       )
+'
+
+test_expect_success 'make_relative_path handles double slashes in GIT_DIR' '
+       >dummy_file &&
+       echo git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file &&
+       git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file
+'
+
+test_expect_success 'relative $GIT_WORK_TREE and git subprocesses' '
+       GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work \
+       test-subprocess --setup-work-tree rev-parse --show-toplevel >actual &&
+       echo "$(pwd)/repo.git/work" >expected &&
+       test_cmp expected actual
+'
+
+test_expect_success 'Multi-worktree setup' '
+       mkdir work &&
+       mkdir -p repo.git/repos/foo &&
+       cp repo.git/HEAD repo.git/index repo.git/repos/foo &&
+       test_might_fail cp repo.git/sharedindex.* repo.git/repos/foo &&
+       sane_unset GIT_DIR GIT_CONFIG GIT_WORK_TREE
+'
+
+test_expect_success 'GIT_DIR set (1)' '
+       echo "gitdir: repo.git/repos/foo" >gitfile &&
+       echo ../.. >repo.git/repos/foo/commondir &&
+       (
+               cd work &&
+               GIT_DIR=../gitfile git rev-parse --git-common-dir >actual &&
+               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'GIT_DIR set (2)' '
+       echo "gitdir: repo.git/repos/foo" >gitfile &&
+       echo "$(pwd)/repo.git" >repo.git/repos/foo/commondir &&
+       (
+               cd work &&
+               GIT_DIR=../gitfile git rev-parse --git-common-dir >actual &&
+               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'Auto discovery' '
+       echo "gitdir: repo.git/repos/foo" >.git &&
+       echo ../.. >repo.git/repos/foo/commondir &&
+       (
+               cd work &&
+               git rev-parse --git-common-dir >actual &&
+               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
+               test_cmp expect actual &&
+               echo haha >data1 &&
+               git add data1 &&
+               git ls-files --full-name :/ | grep data1 >actual &&
+               echo work/data1 >expect &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success '$GIT_DIR/common overrides core.worktree' '
+       mkdir elsewhere &&
+       git --git-dir=repo.git config core.worktree "$TRASH_DIRECTORY/elsewhere" &&
+       echo "gitdir: repo.git/repos/foo" >.git &&
+       echo ../.. >repo.git/repos/foo/commondir &&
+       (
+               cd work &&
+               git rev-parse --git-common-dir >actual &&
+               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
+               test_cmp expect actual &&
+               echo haha >data2 &&
+               git add data2 &&
+               git ls-files --full-name :/ | grep data2 >actual &&
+               echo work/data2 >expect &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success '$GIT_WORK_TREE overrides $GIT_DIR/common' '
+       echo "gitdir: repo.git/repos/foo" >.git &&
+       echo ../.. >repo.git/repos/foo/commondir &&
+       (
+               cd work &&
+               echo haha >data3 &&
+               git --git-dir=../.git --work-tree=. add data3 &&
+               git ls-files --full-name -- :/ | grep data3 >actual &&
+               echo data3 >expect &&
+               test_cmp expect actual
+       )
+'
+
+test_done
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
deleted file mode 100755 (executable)
index cc5b870..0000000
+++ /dev/null
@@ -1,426 +0,0 @@
-#!/bin/sh
-
-test_description='test separate work tree'
-. ./test-lib.sh
-
-test_expect_success 'setup' '
-       EMPTY_TREE=$(git write-tree) &&
-       EMPTY_BLOB=$(git hash-object -t blob --stdin </dev/null) &&
-       CHANGED_BLOB=$(echo changed | git hash-object -t blob --stdin) &&
-       EMPTY_BLOB7=$(echo $EMPTY_BLOB | sed "s/\(.......\).*/\1/") &&
-       CHANGED_BLOB7=$(echo $CHANGED_BLOB | sed "s/\(.......\).*/\1/") &&
-
-       mkdir -p work/sub/dir &&
-       mkdir -p work2 &&
-       mv .git repo.git
-'
-
-test_expect_success 'setup: helper for testing rev-parse' '
-       test_rev_parse() {
-               echo $1 >expected.bare &&
-               echo $2 >expected.inside-git &&
-               echo $3 >expected.inside-worktree &&
-               if test $# -ge 4
-               then
-                       echo $4 >expected.prefix
-               fi &&
-
-               git rev-parse --is-bare-repository >actual.bare &&
-               git rev-parse --is-inside-git-dir >actual.inside-git &&
-               git rev-parse --is-inside-work-tree >actual.inside-worktree &&
-               if test $# -ge 4
-               then
-                       git rev-parse --show-prefix >actual.prefix
-               fi &&
-
-               test_cmp expected.bare actual.bare &&
-               test_cmp expected.inside-git actual.inside-git &&
-               test_cmp expected.inside-worktree actual.inside-worktree &&
-               if test $# -ge 4
-               then
-                       # rev-parse --show-prefix should output
-                       # a single newline when at the top of the work tree,
-                       # but we test for that separately.
-                       test -z "$4" && ! test -s actual.prefix ||
-                       test_cmp expected.prefix actual.prefix
-               fi
-       }
-'
-
-test_expect_success 'setup: core.worktree = relative path' '
-       sane_unset GIT_WORK_TREE &&
-       GIT_DIR=repo.git &&
-       GIT_CONFIG="$(pwd)"/$GIT_DIR/config &&
-       export GIT_DIR GIT_CONFIG &&
-       git config core.worktree ../work
-'
-
-test_expect_success 'outside' '
-       test_rev_parse false false false
-'
-
-test_expect_success 'inside work tree' '
-       (
-               cd work &&
-               GIT_DIR=../repo.git &&
-               GIT_CONFIG="$(pwd)"/$GIT_DIR/config &&
-               test_rev_parse false false true ""
-       )
-'
-
-test_expect_success 'empty prefix is actually written out' '
-       echo >expected &&
-       (
-               cd work &&
-               GIT_DIR=../repo.git &&
-               GIT_CONFIG="$(pwd)"/$GIT_DIR/config &&
-               git rev-parse --show-prefix >../actual
-       ) &&
-       test_cmp expected actual
-'
-
-test_expect_success 'subdir of work tree' '
-       (
-               cd work/sub/dir &&
-               GIT_DIR=../../../repo.git &&
-               GIT_CONFIG="$(pwd)"/$GIT_DIR/config &&
-               test_rev_parse false false true sub/dir/
-       )
-'
-
-test_expect_success 'setup: core.worktree = absolute path' '
-       sane_unset GIT_WORK_TREE &&
-       GIT_DIR=$(pwd)/repo.git &&
-       GIT_CONFIG=$GIT_DIR/config &&
-       export GIT_DIR GIT_CONFIG &&
-       git config core.worktree "$(pwd)/work"
-'
-
-test_expect_success 'outside' '
-       test_rev_parse false false false &&
-       (
-               cd work2 &&
-               test_rev_parse false false false
-       )
-'
-
-test_expect_success 'inside work tree' '
-       (
-               cd work &&
-               test_rev_parse false false true ""
-       )
-'
-
-test_expect_success 'subdir of work tree' '
-       (
-               cd work/sub/dir &&
-               test_rev_parse false false true sub/dir/
-       )
-'
-
-test_expect_success 'setup: GIT_WORK_TREE=relative (override core.worktree)' '
-       GIT_DIR=$(pwd)/repo.git &&
-       GIT_CONFIG=$GIT_DIR/config &&
-       git config core.worktree non-existent &&
-       GIT_WORK_TREE=work &&
-       export GIT_DIR GIT_CONFIG GIT_WORK_TREE
-'
-
-test_expect_success 'outside' '
-       test_rev_parse false false false &&
-       (
-               cd work2 &&
-               test_rev_parse false false false
-       )
-'
-
-test_expect_success 'inside work tree' '
-       (
-               cd work &&
-               GIT_WORK_TREE=. &&
-               test_rev_parse false false true ""
-       )
-'
-
-test_expect_success 'subdir of work tree' '
-       (
-               cd work/sub/dir &&
-               GIT_WORK_TREE=../.. &&
-               test_rev_parse false false true sub/dir/
-       )
-'
-
-test_expect_success 'setup: GIT_WORK_TREE=absolute, below git dir' '
-       mv work repo.git/work &&
-       mv work2 repo.git/work2 &&
-       GIT_DIR=$(pwd)/repo.git &&
-       GIT_CONFIG=$GIT_DIR/config &&
-       GIT_WORK_TREE=$(pwd)/repo.git/work &&
-       export GIT_DIR GIT_CONFIG GIT_WORK_TREE
-'
-
-test_expect_success 'outside' '
-       echo outside &&
-       test_rev_parse false false false
-'
-
-test_expect_success 'in repo.git' '
-       (
-               cd repo.git &&
-               test_rev_parse false true false
-       ) &&
-       (
-               cd repo.git/objects &&
-               test_rev_parse false true false
-       ) &&
-       (
-               cd repo.git/work2 &&
-               test_rev_parse false true false
-       )
-'
-
-test_expect_success 'inside work tree' '
-       (
-               cd repo.git/work &&
-               test_rev_parse false true true ""
-       )
-'
-
-test_expect_success 'subdir of work tree' '
-       (
-               cd repo.git/work/sub/dir &&
-               test_rev_parse false true true sub/dir/
-       )
-'
-
-test_expect_success 'find work tree from repo' '
-       echo sub/dir/untracked >expected &&
-       cat <<-\EOF >repo.git/work/.gitignore &&
-       expected.*
-       actual.*
-       .gitignore
-       EOF
-       >repo.git/work/sub/dir/untracked &&
-       (
-               cd repo.git &&
-               git ls-files --others --exclude-standard >../actual
-       ) &&
-       test_cmp expected actual
-'
-
-test_expect_success 'find work tree from work tree' '
-       echo sub/dir/tracked >expected &&
-       >repo.git/work/sub/dir/tracked &&
-       (
-               cd repo.git/work/sub/dir &&
-               git --git-dir=../../.. add tracked
-       ) &&
-       (
-               cd repo.git &&
-               git ls-files >../actual
-       ) &&
-       test_cmp expected actual
-'
-
-test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
-       (
-               cd repo.git/work/sub/dir &&
-               GIT_DIR=../../.. &&
-               GIT_WORK_TREE=../.. &&
-               GIT_PAGER= &&
-               export GIT_DIR GIT_WORK_TREE GIT_PAGER &&
-
-               git diff --exit-code tracked &&
-               echo changed >tracked &&
-               test_must_fail git diff --exit-code tracked
-       )
-'
-
-test_expect_success 'diff-index respects work tree under .git dir' '
-       cat >diff-index-cached.expected <<-EOF &&
-       :000000 100644 $_z40 $EMPTY_BLOB A      sub/dir/tracked
-       EOF
-       cat >diff-index.expected <<-EOF &&
-       :000000 100644 $_z40 $_z40 A    sub/dir/tracked
-       EOF
-
-       (
-               GIT_DIR=repo.git &&
-               GIT_WORK_TREE=repo.git/work &&
-               export GIT_DIR GIT_WORK_TREE &&
-               git diff-index $EMPTY_TREE >diff-index.actual &&
-               git diff-index --cached $EMPTY_TREE >diff-index-cached.actual
-       ) &&
-       test_cmp diff-index.expected diff-index.actual &&
-       test_cmp diff-index-cached.expected diff-index-cached.actual
-'
-
-test_expect_success 'diff-files respects work tree under .git dir' '
-       cat >diff-files.expected <<-EOF &&
-       :100644 100644 $EMPTY_BLOB $_z40 M      sub/dir/tracked
-       EOF
-
-       (
-               GIT_DIR=repo.git &&
-               GIT_WORK_TREE=repo.git/work &&
-               export GIT_DIR GIT_WORK_TREE &&
-               git diff-files >diff-files.actual
-       ) &&
-       test_cmp diff-files.expected diff-files.actual
-'
-
-test_expect_success 'git diff respects work tree under .git dir' '
-       cat >diff-TREE.expected <<-EOF &&
-       diff --git a/sub/dir/tracked b/sub/dir/tracked
-       new file mode 100644
-       index 0000000..$CHANGED_BLOB7
-       --- /dev/null
-       +++ b/sub/dir/tracked
-       @@ -0,0 +1 @@
-       +changed
-       EOF
-       cat >diff-TREE-cached.expected <<-EOF &&
-       diff --git a/sub/dir/tracked b/sub/dir/tracked
-       new file mode 100644
-       index 0000000..$EMPTY_BLOB7
-       EOF
-       cat >diff-FILES.expected <<-EOF &&
-       diff --git a/sub/dir/tracked b/sub/dir/tracked
-       index $EMPTY_BLOB7..$CHANGED_BLOB7 100644
-       --- a/sub/dir/tracked
-       +++ b/sub/dir/tracked
-       @@ -0,0 +1 @@
-       +changed
-       EOF
-
-       (
-               GIT_DIR=repo.git &&
-               GIT_WORK_TREE=repo.git/work &&
-               export GIT_DIR GIT_WORK_TREE &&
-               git diff $EMPTY_TREE >diff-TREE.actual &&
-               git diff --cached $EMPTY_TREE >diff-TREE-cached.actual &&
-               git diff >diff-FILES.actual
-       ) &&
-       test_cmp diff-TREE.expected diff-TREE.actual &&
-       test_cmp diff-TREE-cached.expected diff-TREE-cached.actual &&
-       test_cmp diff-FILES.expected diff-FILES.actual
-'
-
-test_expect_success 'git grep' '
-       echo dir/tracked >expected.grep &&
-       (
-               cd repo.git/work/sub &&
-               GIT_DIR=../.. &&
-               GIT_WORK_TREE=.. &&
-               export GIT_DIR GIT_WORK_TREE &&
-               git grep -l changed >../../../actual.grep
-       ) &&
-       test_cmp expected.grep actual.grep
-'
-
-test_expect_success 'git commit' '
-       (
-               cd repo.git &&
-               GIT_DIR=. GIT_WORK_TREE=work git commit -a -m done
-       )
-'
-
-test_expect_success 'absolute pathspec should fail gracefully' '
-       (
-               cd repo.git &&
-               test_might_fail git config --unset core.worktree &&
-               test_must_fail git log HEAD -- /home
-       )
-'
-
-test_expect_success 'make_relative_path handles double slashes in GIT_DIR' '
-       >dummy_file &&
-       echo git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file &&
-       git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file
-'
-
-test_expect_success 'relative $GIT_WORK_TREE and git subprocesses' '
-       GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work \
-       test-subprocess --setup-work-tree rev-parse --show-toplevel >actual &&
-       echo "$(pwd)/repo.git/work" >expected &&
-       test_cmp expected actual
-'
-
-test_expect_success 'Multi-worktree setup' '
-       mkdir work &&
-       mkdir -p repo.git/repos/foo &&
-       cp repo.git/HEAD repo.git/index repo.git/repos/foo &&
-       test_might_fail cp repo.git/sharedindex.* repo.git/repos/foo &&
-       sane_unset GIT_DIR GIT_CONFIG GIT_WORK_TREE
-'
-
-test_expect_success 'GIT_DIR set (1)' '
-       echo "gitdir: repo.git/repos/foo" >gitfile &&
-       echo ../.. >repo.git/repos/foo/commondir &&
-       (
-               cd work &&
-               GIT_DIR=../gitfile git rev-parse --git-common-dir >actual &&
-               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
-               test_cmp expect actual
-       )
-'
-
-test_expect_success 'GIT_DIR set (2)' '
-       echo "gitdir: repo.git/repos/foo" >gitfile &&
-       echo "$(pwd)/repo.git" >repo.git/repos/foo/commondir &&
-       (
-               cd work &&
-               GIT_DIR=../gitfile git rev-parse --git-common-dir >actual &&
-               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
-               test_cmp expect actual
-       )
-'
-
-test_expect_success 'Auto discovery' '
-       echo "gitdir: repo.git/repos/foo" >.git &&
-       echo ../.. >repo.git/repos/foo/commondir &&
-       (
-               cd work &&
-               git rev-parse --git-common-dir >actual &&
-               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
-               test_cmp expect actual &&
-               echo haha >data1 &&
-               git add data1 &&
-               git ls-files --full-name :/ | grep data1 >actual &&
-               echo work/data1 >expect &&
-               test_cmp expect actual
-       )
-'
-
-test_expect_success '$GIT_DIR/common overrides core.worktree' '
-       mkdir elsewhere &&
-       git --git-dir=repo.git config core.worktree "$TRASH_DIRECTORY/elsewhere" &&
-       echo "gitdir: repo.git/repos/foo" >.git &&
-       echo ../.. >repo.git/repos/foo/commondir &&
-       (
-               cd work &&
-               git rev-parse --git-common-dir >actual &&
-               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
-               test_cmp expect actual &&
-               echo haha >data2 &&
-               git add data2 &&
-               git ls-files --full-name :/ | grep data2 >actual &&
-               echo work/data2 >expect &&
-               test_cmp expect actual
-       )
-'
-
-test_expect_success '$GIT_WORK_TREE overrides $GIT_DIR/common' '
-       echo "gitdir: repo.git/repos/foo" >.git &&
-       echo ../.. >repo.git/repos/foo/commondir &&
-       (
-               cd work &&
-               echo haha >data3 &&
-               git --git-dir=../.git --work-tree=. add data3 &&
-               git ls-files --full-name -- :/ | grep data3 >actual &&
-               echo data3 >expect &&
-               test_cmp expect actual
-       )
-'
-
-test_done
diff --git a/t/t1509-root-work-tree.sh b/t/t1509-root-work-tree.sh
new file mode 100755 (executable)
index 0000000..553a3f6
--- /dev/null
@@ -0,0 +1,258 @@
+#!/bin/sh
+
+test_description='Test Git when git repository is located at root
+
+This test requires write access in root. Do not bother if you do not
+have a throwaway chroot or VM.
+
+Script t1509/prepare-chroot.sh may help you setup chroot, then you
+can chroot in and execute this test from there.
+'
+
+. ./test-lib.sh
+
+test_cmp_val() {
+       echo "$1" > expected
+       echo "$2" > result
+       test_cmp expected result
+}
+
+test_vars() {
+       test_expect_success "$1: gitdir" '
+               test_cmp_val "'"$2"'" "$(git rev-parse --git-dir)"
+       '
+
+       test_expect_success "$1: worktree" '
+               test_cmp_val "'"$3"'" "$(git rev-parse --show-toplevel)"
+       '
+
+       test_expect_success "$1: prefix" '
+               test_cmp_val "'"$4"'" "$(git rev-parse --show-prefix)"
+       '
+}
+
+test_foobar_root() {
+       test_expect_success 'add relative' '
+               test -z "$(cd / && git ls-files)" &&
+               git add foo/foome &&
+               git add foo/bar/barme &&
+               git add me &&
+               ( cd / && git ls-files --stage ) > result &&
+               test_cmp /ls.expected result &&
+               rm "$(git rev-parse --git-dir)/index"
+       '
+
+       test_expect_success 'add absolute' '
+               test -z "$(cd / && git ls-files)" &&
+               git add /foo/foome &&
+               git add /foo/bar/barme &&
+               git add /me &&
+               ( cd / && git ls-files --stage ) > result &&
+               test_cmp /ls.expected result &&
+               rm "$(git rev-parse --git-dir)/index"
+       '
+
+}
+
+test_foobar_foo() {
+       test_expect_success 'add relative' '
+               test -z "$(cd / && git ls-files)" &&
+               git add foome &&
+               git add bar/barme &&
+               git add ../me &&
+               ( cd / && git ls-files --stage ) > result &&
+               test_cmp /ls.expected result &&
+               rm "$(git rev-parse --git-dir)/index"
+       '
+
+       test_expect_success 'add absolute' '
+               test -z "$(cd / && git ls-files)" &&
+               git add /foo/foome &&
+               git add /foo/bar/barme &&
+               git add /me &&
+               ( cd / && git ls-files --stage ) > result &&
+               test_cmp /ls.expected result &&
+               rm "$(git rev-parse --git-dir)/index"
+       '
+}
+
+test_foobar_foobar() {
+       test_expect_success 'add relative' '
+               test -z "$(cd / && git ls-files)" &&
+               git add ../foome &&
+               git add barme &&
+               git add ../../me &&
+               ( cd / && git ls-files --stage ) > result &&
+               test_cmp /ls.expected result &&
+               rm "$(git rev-parse --git-dir)/index"
+       '
+
+       test_expect_success 'add absolute' '
+               test -z "$(cd / && git ls-files)" &&
+               git add /foo/foome &&
+               git add /foo/bar/barme &&
+               git add /me &&
+               ( cd / && git ls-files --stage ) > result &&
+               test_cmp /ls.expected result &&
+               rm "$(git rev-parse --git-dir)/index"
+       '
+}
+
+if ! test -w /
+then
+       skip_all="Test requiring writable / skipped. Read this test if you want to run it"
+       test_done
+fi
+
+if  test -e /refs || test -e /objects || test -e /info || test -e /hooks ||
+    test -e /.git || test -e /foo || test -e /me
+then
+       skip_all="Skip test that clobbers existing files in /"
+       test_done
+fi
+
+if [ "$IKNOWWHATIAMDOING" != "YES" ]; then
+       skip_all="You must set env var IKNOWWHATIAMDOING=YES in order to run this test"
+       test_done
+fi
+
+if ! test_have_prereq NOT_ROOT
+then
+       skip_all="No you can't run this as root"
+       test_done
+fi
+
+ONE_SHA1=d00491fd7e5bb6fa28c517a0bb32b8b506539d4d
+
+test_expect_success 'setup' '
+       rm -rf /foo &&
+       mkdir /foo &&
+       mkdir /foo/bar &&
+       echo 1 > /foo/foome &&
+       echo 1 > /foo/bar/barme &&
+       echo 1 > /me
+'
+
+say "GIT_DIR absolute, GIT_WORK_TREE set"
+
+test_expect_success 'go to /' 'cd /'
+
+cat >ls.expected <<EOF
+100644 $ONE_SHA1 0     foo/bar/barme
+100644 $ONE_SHA1 0     foo/foome
+100644 $ONE_SHA1 0     me
+EOF
+
+GIT_DIR="$TRASH_DIRECTORY/.git" && export GIT_DIR
+GIT_WORK_TREE=/ && export GIT_WORK_TREE
+
+test_vars 'abs gitdir, root' "$GIT_DIR" "/" ""
+test_foobar_root
+
+test_expect_success 'go to /foo' 'cd /foo'
+
+test_vars 'abs gitdir, foo' "$GIT_DIR" "/" "foo/"
+test_foobar_foo
+
+test_expect_success 'go to /foo/bar' 'cd /foo/bar'
+
+test_vars 'abs gitdir, foo/bar' "$GIT_DIR" "/" "foo/bar/"
+test_foobar_foobar
+
+say "GIT_DIR relative, GIT_WORK_TREE set"
+
+test_expect_success 'go to /' 'cd /'
+
+GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
+GIT_WORK_TREE=/ && export GIT_WORK_TREE
+
+test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
+test_foobar_root
+
+test_expect_success 'go to /foo' 'cd /foo'
+
+GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
+GIT_WORK_TREE=/ && export GIT_WORK_TREE
+
+test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
+test_foobar_foo
+
+test_expect_success 'go to /foo/bar' 'cd /foo/bar'
+
+GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
+GIT_WORK_TREE=/ && export GIT_WORK_TREE
+
+test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/"
+test_foobar_foobar
+
+say "GIT_DIR relative, GIT_WORK_TREE relative"
+
+test_expect_success 'go to /' 'cd /'
+
+GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
+GIT_WORK_TREE=. && export GIT_WORK_TREE
+
+test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
+test_foobar_root
+
+test_expect_success 'go to /' 'cd /foo'
+
+GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
+GIT_WORK_TREE=.. && export GIT_WORK_TREE
+
+test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
+test_foobar_foo
+
+test_expect_success 'go to /foo/bar' 'cd /foo/bar'
+
+GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
+GIT_WORK_TREE=../.. && export GIT_WORK_TREE
+
+test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/"
+test_foobar_foobar
+
+say ".git at root"
+
+unset GIT_DIR
+unset GIT_WORK_TREE
+
+test_expect_success 'go to /' 'cd /'
+test_expect_success 'setup' '
+       rm -rf /.git &&
+       echo "Initialized empty Git repository in /.git/" > expected &&
+       git init > result &&
+       test_cmp expected result
+'
+
+test_vars 'auto gitdir, root' ".git" "/" ""
+test_foobar_root
+
+test_expect_success 'go to /foo' 'cd /foo'
+test_vars 'auto gitdir, foo' "/.git" "/" "foo/"
+test_foobar_foo
+
+test_expect_success 'go to /foo/bar' 'cd /foo/bar'
+test_vars 'auto gitdir, foo/bar' "/.git" "/" "foo/bar/"
+test_foobar_foobar
+
+test_expect_success 'cleanup' 'rm -rf /.git'
+
+say "auto bare gitdir"
+
+# DESTROYYYYY!!!!!
+test_expect_success 'setup' '
+       rm -rf /refs /objects /info /hooks &&
+       rm -f /expected /ls.expected /me /result &&
+       cd / &&
+       echo "Initialized empty Git repository in /" > expected &&
+       git init --bare > result &&
+       test_cmp expected result
+'
+
+test_vars 'auto gitdir, root' "." "" ""
+
+test_expect_success 'go to /foo' 'cd /foo'
+
+test_vars 'auto gitdir, root' "/" "" ""
+
+test_done
diff --git a/t/t1509-root-worktree.sh b/t/t1509-root-worktree.sh
deleted file mode 100755 (executable)
index 553a3f6..0000000
+++ /dev/null
@@ -1,258 +0,0 @@
-#!/bin/sh
-
-test_description='Test Git when git repository is located at root
-
-This test requires write access in root. Do not bother if you do not
-have a throwaway chroot or VM.
-
-Script t1509/prepare-chroot.sh may help you setup chroot, then you
-can chroot in and execute this test from there.
-'
-
-. ./test-lib.sh
-
-test_cmp_val() {
-       echo "$1" > expected
-       echo "$2" > result
-       test_cmp expected result
-}
-
-test_vars() {
-       test_expect_success "$1: gitdir" '
-               test_cmp_val "'"$2"'" "$(git rev-parse --git-dir)"
-       '
-
-       test_expect_success "$1: worktree" '
-               test_cmp_val "'"$3"'" "$(git rev-parse --show-toplevel)"
-       '
-
-       test_expect_success "$1: prefix" '
-               test_cmp_val "'"$4"'" "$(git rev-parse --show-prefix)"
-       '
-}
-
-test_foobar_root() {
-       test_expect_success 'add relative' '
-               test -z "$(cd / && git ls-files)" &&
-               git add foo/foome &&
-               git add foo/bar/barme &&
-               git add me &&
-               ( cd / && git ls-files --stage ) > result &&
-               test_cmp /ls.expected result &&
-               rm "$(git rev-parse --git-dir)/index"
-       '
-
-       test_expect_success 'add absolute' '
-               test -z "$(cd / && git ls-files)" &&
-               git add /foo/foome &&
-               git add /foo/bar/barme &&
-               git add /me &&
-               ( cd / && git ls-files --stage ) > result &&
-               test_cmp /ls.expected result &&
-               rm "$(git rev-parse --git-dir)/index"
-       '
-
-}
-
-test_foobar_foo() {
-       test_expect_success 'add relative' '
-               test -z "$(cd / && git ls-files)" &&
-               git add foome &&
-               git add bar/barme &&
-               git add ../me &&
-               ( cd / && git ls-files --stage ) > result &&
-               test_cmp /ls.expected result &&
-               rm "$(git rev-parse --git-dir)/index"
-       '
-
-       test_expect_success 'add absolute' '
-               test -z "$(cd / && git ls-files)" &&
-               git add /foo/foome &&
-               git add /foo/bar/barme &&
-               git add /me &&
-               ( cd / && git ls-files --stage ) > result &&
-               test_cmp /ls.expected result &&
-               rm "$(git rev-parse --git-dir)/index"
-       '
-}
-
-test_foobar_foobar() {
-       test_expect_success 'add relative' '
-               test -z "$(cd / && git ls-files)" &&
-               git add ../foome &&
-               git add barme &&
-               git add ../../me &&
-               ( cd / && git ls-files --stage ) > result &&
-               test_cmp /ls.expected result &&
-               rm "$(git rev-parse --git-dir)/index"
-       '
-
-       test_expect_success 'add absolute' '
-               test -z "$(cd / && git ls-files)" &&
-               git add /foo/foome &&
-               git add /foo/bar/barme &&
-               git add /me &&
-               ( cd / && git ls-files --stage ) > result &&
-               test_cmp /ls.expected result &&
-               rm "$(git rev-parse --git-dir)/index"
-       '
-}
-
-if ! test -w /
-then
-       skip_all="Test requiring writable / skipped. Read this test if you want to run it"
-       test_done
-fi
-
-if  test -e /refs || test -e /objects || test -e /info || test -e /hooks ||
-    test -e /.git || test -e /foo || test -e /me
-then
-       skip_all="Skip test that clobbers existing files in /"
-       test_done
-fi
-
-if [ "$IKNOWWHATIAMDOING" != "YES" ]; then
-       skip_all="You must set env var IKNOWWHATIAMDOING=YES in order to run this test"
-       test_done
-fi
-
-if ! test_have_prereq NOT_ROOT
-then
-       skip_all="No you can't run this as root"
-       test_done
-fi
-
-ONE_SHA1=d00491fd7e5bb6fa28c517a0bb32b8b506539d4d
-
-test_expect_success 'setup' '
-       rm -rf /foo &&
-       mkdir /foo &&
-       mkdir /foo/bar &&
-       echo 1 > /foo/foome &&
-       echo 1 > /foo/bar/barme &&
-       echo 1 > /me
-'
-
-say "GIT_DIR absolute, GIT_WORK_TREE set"
-
-test_expect_success 'go to /' 'cd /'
-
-cat >ls.expected <<EOF
-100644 $ONE_SHA1 0     foo/bar/barme
-100644 $ONE_SHA1 0     foo/foome
-100644 $ONE_SHA1 0     me
-EOF
-
-GIT_DIR="$TRASH_DIRECTORY/.git" && export GIT_DIR
-GIT_WORK_TREE=/ && export GIT_WORK_TREE
-
-test_vars 'abs gitdir, root' "$GIT_DIR" "/" ""
-test_foobar_root
-
-test_expect_success 'go to /foo' 'cd /foo'
-
-test_vars 'abs gitdir, foo' "$GIT_DIR" "/" "foo/"
-test_foobar_foo
-
-test_expect_success 'go to /foo/bar' 'cd /foo/bar'
-
-test_vars 'abs gitdir, foo/bar' "$GIT_DIR" "/" "foo/bar/"
-test_foobar_foobar
-
-say "GIT_DIR relative, GIT_WORK_TREE set"
-
-test_expect_success 'go to /' 'cd /'
-
-GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
-GIT_WORK_TREE=/ && export GIT_WORK_TREE
-
-test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
-test_foobar_root
-
-test_expect_success 'go to /foo' 'cd /foo'
-
-GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
-GIT_WORK_TREE=/ && export GIT_WORK_TREE
-
-test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
-test_foobar_foo
-
-test_expect_success 'go to /foo/bar' 'cd /foo/bar'
-
-GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
-GIT_WORK_TREE=/ && export GIT_WORK_TREE
-
-test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/"
-test_foobar_foobar
-
-say "GIT_DIR relative, GIT_WORK_TREE relative"
-
-test_expect_success 'go to /' 'cd /'
-
-GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
-GIT_WORK_TREE=. && export GIT_WORK_TREE
-
-test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
-test_foobar_root
-
-test_expect_success 'go to /' 'cd /foo'
-
-GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
-GIT_WORK_TREE=.. && export GIT_WORK_TREE
-
-test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
-test_foobar_foo
-
-test_expect_success 'go to /foo/bar' 'cd /foo/bar'
-
-GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
-GIT_WORK_TREE=../.. && export GIT_WORK_TREE
-
-test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/"
-test_foobar_foobar
-
-say ".git at root"
-
-unset GIT_DIR
-unset GIT_WORK_TREE
-
-test_expect_success 'go to /' 'cd /'
-test_expect_success 'setup' '
-       rm -rf /.git &&
-       echo "Initialized empty Git repository in /.git/" > expected &&
-       git init > result &&
-       test_cmp expected result
-'
-
-test_vars 'auto gitdir, root' ".git" "/" ""
-test_foobar_root
-
-test_expect_success 'go to /foo' 'cd /foo'
-test_vars 'auto gitdir, foo' "/.git" "/" "foo/"
-test_foobar_foo
-
-test_expect_success 'go to /foo/bar' 'cd /foo/bar'
-test_vars 'auto gitdir, foo/bar' "/.git" "/" "foo/bar/"
-test_foobar_foobar
-
-test_expect_success 'cleanup' 'rm -rf /.git'
-
-say "auto bare gitdir"
-
-# DESTROYYYYY!!!!!
-test_expect_success 'setup' '
-       rm -rf /refs /objects /info /hooks &&
-       rm -f /expected /ls.expected /me /result &&
-       cd / &&
-       echo "Initialized empty Git repository in /" > expected &&
-       git init --bare > result &&
-       test_cmp expected result
-'
-
-test_vars 'auto gitdir, root' "." "" ""
-
-test_expect_success 'go to /foo' 'cd /foo'
-
-test_vars 'auto gitdir, root' "/" "" ""
-
-test_done
index c402d8d3d7c7e053373ffd98491ae0160481f3ba..c7320121ecfa74dce8389d3790364501c8bb12b8 100755 (executable)
@@ -25,7 +25,8 @@ test_expect_success 'push to update (protected)' '
        (
                cd dst &&
                test_commit D &&
-               test_must_fail git push --force-with-lease=master:master origin master
+               test_must_fail git push --force-with-lease=master:master origin master 2>err &&
+               grep "stale info" err
        ) &&
        git ls-remote . refs/heads/master >expect &&
        git ls-remote src refs/heads/master >actual &&
@@ -37,7 +38,8 @@ test_expect_success 'push to update (protected, forced)' '
        (
                cd dst &&
                test_commit D &&
-               git push --force --force-with-lease=master:master origin master
+               git push --force --force-with-lease=master:master origin master 2>err &&
+               grep "forced update" err
        ) &&
        git ls-remote dst refs/heads/master >expect &&
        git ls-remote src refs/heads/master >actual &&
@@ -101,7 +103,8 @@ test_expect_success 'push to update (allowed, tracking)' '
        (
                cd dst &&
                test_commit D &&
-               git push --force-with-lease=master origin master
+               git push --force-with-lease=master origin master 2>err &&
+               ! grep "forced update" err
        ) &&
        git ls-remote dst refs/heads/master >expect &&
        git ls-remote src refs/heads/master >actual &&
@@ -114,7 +117,8 @@ test_expect_success 'push to update (allowed even though no-ff)' '
                cd dst &&
                git reset --hard HEAD^ &&
                test_commit D &&
-               git push --force-with-lease=master origin master
+               git push --force-with-lease=master origin master 2>err &&
+               grep "forced update" err
        ) &&
        git ls-remote dst refs/heads/master >expect &&
        git ls-remote src refs/heads/master >actual &&
@@ -147,7 +151,8 @@ test_expect_success 'push to delete (allowed)' '
        setup_srcdst_basic &&
        (
                cd dst &&
-               git push --force-with-lease=master origin :master
+               git push --force-with-lease=master origin :master 2>err &&
+               grep deleted err
        ) &&
        >expect &&
        git ls-remote src refs/heads/master >actual &&
index 190ee903cf6269071809e82d61d6065f1de679c6..20aee43f95ab3cc38b8671a233089873fe374777 100755 (executable)
@@ -346,4 +346,17 @@ test_expect_success 'conflict at EOF without LF resolved by --union' \
         printf "line1\nline2\nline3x\nline3y" >expect.txt &&
         test_cmp expect.txt output.txt'
 
+test_expect_success 'conflict sections match existing line endings' '
+       printf "1\\r\\n2\\r\\n3" >crlf-orig.txt &&
+       printf "1\\r\\n2\\r\\n4" >crlf-diff1.txt &&
+       printf "1\\r\\n2\\r\\n5" >crlf-diff2.txt &&
+       test_must_fail git -c core.eol=crlf merge-file -p \
+               crlf-diff1.txt crlf-orig.txt crlf-diff2.txt >crlf.txt &&
+       test $(tr "\015" Q <crlf.txt | grep "^[<=>].*Q$" | wc -l) = 3 &&
+       test $(tr "\015" Q <crlf.txt | grep "[345]Q$" | wc -l) = 3 &&
+       test_must_fail git -c core.eol=crlf merge-file -p \
+               nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >nolf.txt &&
+       test $(tr "\015" Q <nolf.txt | grep "^[<=>].*Q$" | wc -l) = 0
+'
+
 test_done
diff --git a/t/t7409-submodule-detached-work-tree.sh b/t/t7409-submodule-detached-work-tree.sh
new file mode 100755 (executable)
index 0000000..c207171
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/sh
+#
+# Copyright (c) 2012 Daniel Graña
+#
+
+test_description='Test submodules on detached working tree
+
+This test verifies that "git submodule" initialization, update and addition works
+on detahced working trees
+'
+
+TEST_NO_CREATE_REPO=1
+. ./test-lib.sh
+
+test_expect_success 'submodule on detached working tree' '
+       git init --bare remote &&
+       test_create_repo bundle1 &&
+       (
+               cd bundle1 &&
+               test_commit "shoot" &&
+               git rev-parse --verify HEAD >../expect
+       ) &&
+       mkdir home &&
+       (
+               cd home &&
+               GIT_WORK_TREE="$(pwd)" &&
+               GIT_DIR="$(pwd)/.dotfiles" &&
+               export GIT_WORK_TREE GIT_DIR &&
+               git clone --bare ../remote .dotfiles &&
+               git submodule add ../bundle1 .vim/bundle/sogood &&
+               test_commit "sogood" &&
+               (
+                       unset GIT_WORK_TREE GIT_DIR &&
+                       cd .vim/bundle/sogood &&
+                       git rev-parse --verify HEAD >actual &&
+                       test_cmp ../../../../expect actual
+               ) &&
+               git push origin master
+       ) &&
+       mkdir home2 &&
+       (
+               cd home2 &&
+               git clone --bare ../remote .dotfiles &&
+               GIT_WORK_TREE="$(pwd)" &&
+               GIT_DIR="$(pwd)/.dotfiles" &&
+               export GIT_WORK_TREE GIT_DIR &&
+               git checkout master &&
+               git submodule update --init &&
+               (
+                       unset GIT_WORK_TREE GIT_DIR &&
+                       cd .vim/bundle/sogood &&
+                       git rev-parse --verify HEAD >actual &&
+                       test_cmp ../../../../expect actual
+               )
+       )
+'
+
+test_expect_success 'submodule on detached working pointed by core.worktree' '
+       mkdir home3 &&
+       (
+               cd home3 &&
+               GIT_DIR="$(pwd)/.dotfiles" &&
+               export GIT_DIR &&
+               git clone --bare ../remote "$GIT_DIR" &&
+               git config core.bare false &&
+               git config core.worktree .. &&
+               git checkout master &&
+               git submodule add ../bundle1 .vim/bundle/dupe &&
+               test_commit "dupe" &&
+               git push origin master
+       ) &&
+       (
+               cd home &&
+               GIT_DIR="$(pwd)/.dotfiles" &&
+               export GIT_DIR &&
+               git config core.bare false &&
+               git config core.worktree .. &&
+               git pull &&
+               git submodule update --init &&
+               test -f .vim/bundle/dupe/shoot.t
+       )
+'
+
+test_done
diff --git a/t/t7409-submodule-detached-worktree.sh b/t/t7409-submodule-detached-worktree.sh
deleted file mode 100755 (executable)
index c207171..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2012 Daniel Graña
-#
-
-test_description='Test submodules on detached working tree
-
-This test verifies that "git submodule" initialization, update and addition works
-on detahced working trees
-'
-
-TEST_NO_CREATE_REPO=1
-. ./test-lib.sh
-
-test_expect_success 'submodule on detached working tree' '
-       git init --bare remote &&
-       test_create_repo bundle1 &&
-       (
-               cd bundle1 &&
-               test_commit "shoot" &&
-               git rev-parse --verify HEAD >../expect
-       ) &&
-       mkdir home &&
-       (
-               cd home &&
-               GIT_WORK_TREE="$(pwd)" &&
-               GIT_DIR="$(pwd)/.dotfiles" &&
-               export GIT_WORK_TREE GIT_DIR &&
-               git clone --bare ../remote .dotfiles &&
-               git submodule add ../bundle1 .vim/bundle/sogood &&
-               test_commit "sogood" &&
-               (
-                       unset GIT_WORK_TREE GIT_DIR &&
-                       cd .vim/bundle/sogood &&
-                       git rev-parse --verify HEAD >actual &&
-                       test_cmp ../../../../expect actual
-               ) &&
-               git push origin master
-       ) &&
-       mkdir home2 &&
-       (
-               cd home2 &&
-               git clone --bare ../remote .dotfiles &&
-               GIT_WORK_TREE="$(pwd)" &&
-               GIT_DIR="$(pwd)/.dotfiles" &&
-               export GIT_WORK_TREE GIT_DIR &&
-               git checkout master &&
-               git submodule update --init &&
-               (
-                       unset GIT_WORK_TREE GIT_DIR &&
-                       cd .vim/bundle/sogood &&
-                       git rev-parse --verify HEAD >actual &&
-                       test_cmp ../../../../expect actual
-               )
-       )
-'
-
-test_expect_success 'submodule on detached working pointed by core.worktree' '
-       mkdir home3 &&
-       (
-               cd home3 &&
-               GIT_DIR="$(pwd)/.dotfiles" &&
-               export GIT_DIR &&
-               git clone --bare ../remote "$GIT_DIR" &&
-               git config core.bare false &&
-               git config core.worktree .. &&
-               git checkout master &&
-               git submodule add ../bundle1 .vim/bundle/dupe &&
-               test_commit "dupe" &&
-               git push origin master
-       ) &&
-       (
-               cd home &&
-               GIT_DIR="$(pwd)/.dotfiles" &&
-               export GIT_DIR &&
-               git config core.bare false &&
-               git config core.worktree .. &&
-               git pull &&
-               git submodule update --init &&
-               test -f .vim/bundle/dupe/shoot.t
-       )
-'
-
-test_done
index bd4b02e9dbf9560cf1285bb6607be83964ecc40a..51e4a88c333463e23957eb07139b01a3de1a1a0e 100644 (file)
@@ -907,9 +907,11 @@ yes () {
                y="$*"
        fi
 
-       while echo "$y"
+       i=0
+       while test $i -lt 99
        do
-               :
+               echo "$y"
+               i=$(($i+1))
        done
 }
 
index 981f810e80008d878d6a5af1331c89dc093c5927..6181a66f1ee2e1e45d7d8b2c88d312746473661f 100644 (file)
@@ -176,10 +176,10 @@ struct worktree **get_worktrees(void)
                        if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
                                continue;
 
-                               if ((linked = get_linked_worktree(d->d_name))) {
-                                       ALLOC_GROW(list, counter + 1, alloc);
-                                       list[counter++] = linked;
-                               }
+                       if ((linked = get_linked_worktree(d->d_name))) {
+                               ALLOC_GROW(list, counter + 1, alloc);
+                               list[counter++] = linked;
+                       }
                }
                closedir(dir);
        }
index 625198e0585c52c20c778790c82126efd1b57009..d98f430c912bead3ee5381eafd195dde4d709c47 100644 (file)
@@ -109,7 +109,7 @@ static int xdl_merge_cmp_lines(xdfenv_t *xe1, int i1, xdfenv_t *xe2, int i2,
        return 0;
 }
 
-static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add_nl, char *dest)
+static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
 {
        xrecord_t **recs;
        int size = 0;
@@ -125,6 +125,12 @@ static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add
        if (add_nl) {
                i = recs[count - 1]->size;
                if (i == 0 || recs[count - 1]->ptr[i - 1] != '\n') {
+                       if (needs_cr) {
+                               if (dest)
+                                       dest[size] = '\r';
+                               size++;
+                       }
+
                        if (dest)
                                dest[size] = '\n';
                        size++;
@@ -133,14 +139,58 @@ static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add
        return size;
 }
 
-static int xdl_recs_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest)
+static int xdl_recs_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
+{
+       return xdl_recs_copy_0(0, xe, i, count, needs_cr, add_nl, dest);
+}
+
+static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
+{
+       return xdl_recs_copy_0(1, xe, i, count, needs_cr, add_nl, dest);
+}
+
+/*
+ * Returns 1 if the i'th line ends in CR/LF (if it is the last line and
+ * has no eol, the preceding line, if any), 0 if it ends in LF-only, and
+ * -1 if the line ending cannot be determined.
+ */
+static int is_eol_crlf(xdfile_t *file, int i)
 {
-       return xdl_recs_copy_0(0, xe, i, count, add_nl, dest);
+       long size;
+
+       if (i < file->nrec - 1)
+               /* All lines before the last *must* end in LF */
+               return (size = file->recs[i]->size) > 1 &&
+                       file->recs[i]->ptr[size - 2] == '\r';
+       if (!file->nrec)
+               /* Cannot determine eol style from empty file */
+               return -1;
+       if ((size = file->recs[i]->size) &&
+                       file->recs[i]->ptr[size - 1] == '\n')
+               /* Last line; ends in LF; Is it CR/LF? */
+               return size > 1 &&
+                       file->recs[i]->ptr[size - 2] == '\r';
+       if (!i)
+               /* The only line has no eol */
+               return -1;
+       /* Determine eol from second-to-last line */
+       return (size = file->recs[i - 1]->size) > 1 &&
+               file->recs[i - 1]->ptr[size - 2] == '\r';
 }
 
-static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest)
+static int is_cr_needed(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t *m)
 {
-       return xdl_recs_copy_0(1, xe, i, count, add_nl, dest);
+       int needs_cr;
+
+       /* Match post-images' preceding, or first, lines' end-of-line style */
+       needs_cr = is_eol_crlf(&xe1->xdf2, m->i1 ? m->i1 - 1 : 0);
+       if (needs_cr)
+               needs_cr = is_eol_crlf(&xe2->xdf2, m->i2 ? m->i2 - 1 : 0);
+       /* Look at pre-image's first line, unless we already settled on LF */
+       if (needs_cr)
+               needs_cr = is_eol_crlf(&xe1->xdf1, 0);
+       /* If still undecided, use LF-only */
+       return needs_cr < 0 ? 0 : needs_cr;
 }
 
 static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
@@ -152,16 +202,17 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
        int marker1_size = (name1 ? strlen(name1) + 1 : 0);
        int marker2_size = (name2 ? strlen(name2) + 1 : 0);
        int marker3_size = (name3 ? strlen(name3) + 1 : 0);
+       int needs_cr = is_cr_needed(xe1, xe2, m);
 
        if (marker_size <= 0)
                marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
 
        /* Before conflicting part */
-       size += xdl_recs_copy(xe1, i, m->i1 - i, 0,
+       size += xdl_recs_copy(xe1, i, m->i1 - i, 0, 0,
                              dest ? dest + size : NULL);
 
        if (!dest) {
-               size += marker_size + 1 + marker1_size;
+               size += marker_size + 1 + needs_cr + marker1_size;
        } else {
                memset(dest + size, '<', marker_size);
                size += marker_size;
@@ -170,17 +221,19 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
                        memcpy(dest + size + 1, name1, marker1_size - 1);
                        size += marker1_size;
                }
+               if (needs_cr)
+                       dest[size++] = '\r';
                dest[size++] = '\n';
        }
 
        /* Postimage from side #1 */
-       size += xdl_recs_copy(xe1, m->i1, m->chg1, 1,
+       size += xdl_recs_copy(xe1, m->i1, m->chg1, needs_cr, 1,
                              dest ? dest + size : NULL);
 
        if (style == XDL_MERGE_DIFF3) {
                /* Shared preimage */
                if (!dest) {
-                       size += marker_size + 1 + marker3_size;
+                       size += marker_size + 1 + needs_cr + marker3_size;
                } else {
                        memset(dest + size, '|', marker_size);
                        size += marker_size;
@@ -189,25 +242,29 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
                                memcpy(dest + size + 1, name3, marker3_size - 1);
                                size += marker3_size;
                        }
+                       if (needs_cr)
+                               dest[size++] = '\r';
                        dest[size++] = '\n';
                }
-               size += xdl_orig_copy(xe1, m->i0, m->chg0, 1,
+               size += xdl_orig_copy(xe1, m->i0, m->chg0, needs_cr, 1,
                                      dest ? dest + size : NULL);
        }
 
        if (!dest) {
-               size += marker_size + 1;
+               size += marker_size + 1 + needs_cr;
        } else {
                memset(dest + size, '=', marker_size);
                size += marker_size;
+               if (needs_cr)
+                       dest[size++] = '\r';
                dest[size++] = '\n';
        }
 
        /* Postimage from side #2 */
-       size += xdl_recs_copy(xe2, m->i2, m->chg2, 1,
+       size += xdl_recs_copy(xe2, m->i2, m->chg2, needs_cr, 1,
                              dest ? dest + size : NULL);
        if (!dest) {
-               size += marker_size + 1 + marker2_size;
+               size += marker_size + 1 + needs_cr + marker2_size;
        } else {
                memset(dest + size, '>', marker_size);
                size += marker_size;
@@ -216,6 +273,8 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
                        memcpy(dest + size + 1, name2, marker2_size - 1);
                        size += marker2_size;
                }
+               if (needs_cr)
+                       dest[size++] = '\r';
                dest[size++] = '\n';
        }
        return size;
@@ -241,21 +300,24 @@ static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
                                                  marker_size);
                else if (m->mode & 3) {
                        /* Before conflicting part */
-                       size += xdl_recs_copy(xe1, i, m->i1 - i, 0,
+                       size += xdl_recs_copy(xe1, i, m->i1 - i, 0, 0,
                                              dest ? dest + size : NULL);
                        /* Postimage from side #1 */
-                       if (m->mode & 1)
-                               size += xdl_recs_copy(xe1, m->i1, m->chg1, (m->mode & 2),
+                       if (m->mode & 1) {
+                               int needs_cr = is_cr_needed(xe1, xe2, m);
+
+                               size += xdl_recs_copy(xe1, m->i1, m->chg1, needs_cr, (m->mode & 2),
                                                      dest ? dest + size : NULL);
+                       }
                        /* Postimage from side #2 */
                        if (m->mode & 2)
-                               size += xdl_recs_copy(xe2, m->i2, m->chg2, 0,
+                               size += xdl_recs_copy(xe2, m->i2, m->chg2, 0, 0,
                                                      dest ? dest + size : NULL);
                } else
                        continue;
                i = m->i1 + m->chg1;
        }
-       size += xdl_recs_copy(xe1, i, xe1->xdf2.nrec - i, 0,
+       size += xdl_recs_copy(xe1, i, xe1->xdf2.nrec - i, 0, 0,
                              dest ? dest + size : NULL);
        return size;
 }