@matheusbsbs / matheus-bagliano / commits / 723024d696
Fork 0

Handle core.symlinks=false case in merge-recursive.

If the file system does not support symbolic links (core.symlinks=false), merge-recursive must write the merged symbolic link text into a regular file. While we are here, fix a tiny memory leak in the if-branch that writes real symbolic links. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Sixt committed Mar 3, 2007 at 20:32 UTC 723024d696a47556baac77700e47fef288691f37
2 files changed +64 -1
merge-recursive.c
+2 -1
@@ -570,7 +570,7 @@ static void update_file_flags(const unsigned char *sha,
570 if (type != OBJ_BLOB)
571 die("blob expected for %s '%s'", sha1_to_hex(sha), path);
572
573 - if (S_ISREG(mode)) {
573 + if (S_ISREG(mode) || (!has_symlinks && S_ISLNK(mode))) {
574 int fd;
575 if (mkdir_p(path, 0777))
576 die("failed to create path %s: %s", path, strerror(errno));
@@ -591,6 +591,7 @@ static void update_file_flags(const unsigned char *sha,
591 mkdir_p(path, 0777);
592 unlink(path);
593 symlink(lnk, path);
594 + free(lnk);
595 } else
596 die("do not know what to do with %06o %s '%s'",
597 mode, sha1_to_hex(sha), path);
t/t6025-merge-symlinks.sh new
+62
@@ -0,0 +1,62 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2007 Johannes Sixt
4 +#
5 +
6 +test_description='merging symlinks on filesystem w/o symlink support.
7 +
8 +This tests that git-merge-recursive writes merge results as plain files
9 +if core.symlinks is false.'
10 +
11 +. ./test-lib.sh
12 +
13 +test_expect_success \
14 +'setup' '
15 +git-config core.symlinks false &&
16 +> file &&
17 +git-add file &&
18 +git-commit -m initial &&
19 +git-branch b-symlink &&
20 +git-branch b-file &&
21 +l=$(echo -n file | git-hash-object -t blob -w --stdin) &&
22 +echo "120000 $l symlink" | git-update-index --index-info &&
23 +git-commit -m master &&
24 +git-checkout b-symlink &&
25 +l=$(echo -n file-different | git-hash-object -t blob -w --stdin) &&
26 +echo "120000 $l symlink" | git-update-index --index-info &&
27 +git-commit -m b-symlink &&
28 +git-checkout b-file &&
29 +echo plain-file > symlink &&
30 +git-add symlink &&
31 +git-commit -m b-file'
32 +
33 +test_expect_failure \
34 +'merge master into b-symlink, which has a different symbolic link' '
35 +! git-checkout b-symlink ||
36 +git-merge master'
37 +
38 +test_expect_success \
39 +'the merge result must be a file' '
40 +test -f symlink'
41 +
42 +test_expect_failure \
43 +'merge master into b-file, which has a file instead of a symbolic link' '
44 +! (git-reset --hard &&
45 +git-checkout b-file) ||
46 +git-merge master'
47 +
48 +test_expect_success \
49 +'the merge result must be a file' '
50 +test -f symlink'
51 +
52 +test_expect_failure \
53 +'merge b-file, which has a file instead of a symbolic link, into master' '
54 +! (git-reset --hard &&
55 +git-checkout master) ||
56 +git-merge b-file'
57 +
58 +test_expect_success \
59 +'the merge result must be a file' '
60 +test -f symlink'
61 +
62 +test_done