Code

Merge branch 'js/merge-recursive'
authorJunio C Hamano <gitster@pobox.com>
Mon, 9 Jun 2008 23:13:10 +0000 (16:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Jun 2008 23:13:10 +0000 (16:13 -0700)
* js/merge-recursive:
  merge-recursive: respect core.autocrlf when writing out the result
  Add testcase for merging in a CRLF repo

builtin-merge-recursive.c
t/t6033-merge-crlf.sh [new file with mode: 0755]

index 362c290028d68ebc2e589d424bc42cd5e8630a4e..4aa28a1babbb275df8110fd80311f34a12fea750 100644 (file)
@@ -555,9 +555,19 @@ static void update_file_flags(const unsigned char *sha,
                        die("cannot read object %s '%s'", sha1_to_hex(sha), path);
                if (type != OBJ_BLOB)
                        die("blob expected for %s '%s'", sha1_to_hex(sha), path);
+               if (S_ISREG(mode)) {
+                       struct strbuf strbuf;
+                       strbuf_init(&strbuf, 0);
+                       if (convert_to_working_tree(path, buf, size, &strbuf)) {
+                               free(buf);
+                               size = strbuf.len;
+                               buf = strbuf_detach(&strbuf, NULL);
+                       }
+               }
 
                if (make_room_for_path(path) < 0) {
                        update_wd = 0;
+                       free(buf);
                        goto update_index;
                }
                if (S_ISREG(mode) || (!has_symlinks && S_ISLNK(mode))) {
@@ -580,6 +590,7 @@ static void update_file_flags(const unsigned char *sha,
                } else
                        die("do not know what to do with %06o %s '%s'",
                            mode, sha1_to_hex(sha), path);
+               free(buf);
        }
  update_index:
        if (update_cache)
diff --git a/t/t6033-merge-crlf.sh b/t/t6033-merge-crlf.sh
new file mode 100755 (executable)
index 0000000..75d9602
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+append_cr () {
+       sed -e 's/$/Q/' | tr Q '\015'
+}
+
+remove_cr () {
+       tr '\015' Q | sed -e 's/Q$//'
+}
+
+test_description='merge conflict in crlf repo
+
+               b---M
+              /   /
+       initial---a
+
+'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+       git config core.autocrlf true &&
+       echo foo | append_cr >file &&
+       git add file &&
+       git commit -m "Initial" &&
+       git tag initial &&
+       git branch side &&
+       echo line from a | append_cr >file &&
+       git commit -m "add line from a" file &&
+       git tag a &&
+       git checkout side &&
+       echo line from b | append_cr >file &&
+       git commit -m "add line from b" file &&
+       git tag b &&
+       git checkout master
+'
+
+test_expect_success 'Check "ours" is CRLF' '
+       git reset --hard initial &&
+       git merge side -s ours &&
+       cat file | remove_cr | append_cr >file.temp &&
+       test_cmp file file.temp
+'
+
+test_expect_success 'Check that conflict file is CRLF' '
+       git reset --hard a &&
+       test_must_fail git merge side &&
+       cat file | remove_cr | append_cr >file.temp &&
+       test_cmp file file.temp
+'
+
+test_done