]> asedeno.scripts.mit.edu Git - git.git/commitdiff
Merge branch 'cb/leading-path-removal'
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 Nov 2010 01:52:36 +0000 (17:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Nov 2010 01:52:36 +0000 (17:52 -0800)
* cb/leading-path-removal:
  use persistent memory for rejected paths
  do not overwrite files in leading path
  lstat_cache: optionally return match_len
  add function check_ok_to_remove()
  t7607: add leading-path tests
  t7607: use test-lib functions and check MERGE_HEAD

Conflicts:
t/t7607-merge-overwrite.sh

1  2 
cache.h
t/t7607-merge-overwrite.sh

diff --combined cache.h
index 33decd942d4985c8efc1c75fd3fa2f4adf4a56ca,5cfee34e2fa749165e090616d4a8a534377e2010..d85ce86f7fd72ee90553241316c1cf6d84a2898d
+++ b/cache.h
@@@ -445,7 -445,7 +445,7 @@@ extern int init_db(const char *template
   * at least 'nr' entries; the number of entries currently allocated
   * is 'alloc', using the standard growing factor alloc_nr() macro.
   *
 - * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
 + * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
   */
  #define ALLOC_GROW(x, nr, alloc) \
        do { \
@@@ -859,7 -859,7 +859,7 @@@ struct cache_def 
  
  extern int has_symlink_leading_path(const char *name, int len);
  extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
- extern int has_symlink_or_noent_leading_path(const char *name, int len);
+ extern int check_leading_path(const char *name, int len);
  extern int has_dirs_only_path(const char *name, int len, int prefix_len);
  extern void schedule_dir_for_removal(const char *name, int len);
  extern void remove_scheduled_dirs(void);
index 3988900fc33f0f5f9cdd416096df619aec2d577e,9137866e1a7d0dfed7dd55f089a0c3ecd420237c..4d5ce4e682c1ea69034c3f7789a8ac0c89b12466
@@@ -7,48 -7,54 +7,54 @@@ Do not overwrite changes.
  . ./test-lib.sh
  
  test_expect_success 'setup' '
-       echo c0 > c0.c &&
-       git add c0.c &&
-       git commit -m c0 &&
-       git tag c0 &&
-       echo c1 > c1.c &&
-       git add c1.c &&
-       git commit -m c1 &&
-       git tag c1 &&
+       test_commit c0 c0.c &&
+       test_commit c1 c1.c &&
+       test_commit c1a c1.c "c1 a" &&
        git reset --hard c0 &&
-       echo c2 > c2.c &&
-       git add c2.c &&
-       git commit -m c2 &&
-       git tag c2 &&
-       git reset --hard c1 &&
-       echo "c1 a" > c1.c &&
-       git add c1.c &&
-       git commit -m "c1 a" &&
-       git tag c1a &&
+       test_commit c2 c2.c &&
+       git reset --hard c0 &&
+       mkdir sub &&
+       echo "sub/f" > sub/f &&
+       mkdir sub2 &&
+       echo "sub2/f" > sub2/f &&
+       git add sub/f sub2/f &&
+       git commit -m sub &&
+       git tag sub &&
        echo "VERY IMPORTANT CHANGES" > important
  '
  
  test_expect_success 'will not overwrite untracked file' '
        git reset --hard c1 &&
-       cat important > c2.c &&
+       cp important c2.c &&
        test_must_fail git merge c2 &&
+       test_path_is_missing .git/MERGE_HEAD &&
        test_cmp important c2.c
  '
  
+ test_expect_success 'will overwrite tracked file' '
+       git reset --hard c1 &&
+       cp important c2.c &&
+       git add c2.c &&
+       git commit -m important &&
+       git checkout c2
+ '
  test_expect_success 'will not overwrite new file' '
        git reset --hard c1 &&
-       cat important > c2.c &&
+       cp important c2.c &&
        git add c2.c &&
        test_must_fail git merge c2 &&
+       test_path_is_missing .git/MERGE_HEAD &&
        test_cmp important c2.c
  '
  
  test_expect_success 'will not overwrite staged changes' '
        git reset --hard c1 &&
-       cat important > c2.c &&
+       cp important c2.c &&
        git add c2.c &&
        rm c2.c &&
        test_must_fail git merge c2 &&
+       test_path_is_missing .git/MERGE_HEAD &&
        git checkout c2.c &&
        test_cmp important c2.c
  '
@@@ -57,7 -63,7 +63,7 @@@ test_expect_success 'will not overwrit
        git reset --hard c1 &&
        git rm c1.c &&
        git commit -m "rm c1.c" &&
-       cat important > c1.c &&
+       cp important c1.c &&
        test_must_fail git merge c1a &&
        test_cmp important c1.c
  '
@@@ -66,9 -72,10 +72,10 @@@ test_expect_success 'will not overwrit
        git reset --hard c1 &&
        git rm c1.c &&
        git commit -m "rm c1.c" &&
-       cat important > c1.c &&
+       cp important c1.c &&
        git add c1.c &&
        test_must_fail git merge c1a &&
+       test_path_is_missing .git/MERGE_HEAD &&
        test_cmp important c1.c
  '
  
@@@ -76,28 -83,61 +83,77 @@@ test_expect_success 'will not overwrit
        git reset --hard c1 &&
        git rm c1.c &&
        git commit -m "rm c1.c" &&
-       cat important > c1.c &&
+       cp important c1.c &&
        git add c1.c &&
        rm c1.c &&
        test_must_fail git merge c1a &&
+       test_path_is_missing .git/MERGE_HEAD &&
        git checkout c1.c &&
        test_cmp important c1.c
  '
  
+ test_expect_success 'will not overwrite untracked subtree' '
+       git reset --hard c0 &&
+       rm -rf sub &&
+       mkdir -p sub/f &&
+       cp important sub/f/important &&
+       test_must_fail git merge sub &&
+       test_path_is_missing .git/MERGE_HEAD &&
+       test_cmp important sub/f/important
+ '
+ cat >expect <<\EOF
+ error: The following untracked working tree files would be overwritten by merge:
+       sub
+       sub2
+ Please move or remove them before you can merge.
+ EOF
+ test_expect_success 'will not overwrite untracked file in leading path' '
+       git reset --hard c0 &&
+       rm -rf sub &&
+       cp important sub &&
+       cp important sub2 &&
+       test_must_fail git merge sub 2>out &&
+       test_cmp out expect &&
+       test_path_is_missing .git/MERGE_HEAD &&
+       test_cmp important sub &&
+       test_cmp important sub2 &&
+       rm -f sub sub2
+ '
+ test_expect_failure SYMLINKS 'will not overwrite untracked symlink in leading path' '
+       git reset --hard c0 &&
+       rm -rf sub &&
+       mkdir sub2 &&
+       ln -s sub2 sub &&
+       test_must_fail git merge sub &&
+       test_path_is_missing .git/MERGE_HEAD
+ '
+ test_expect_success SYMLINKS 'will not be confused by symlink in leading path' '
+       git reset --hard c0 &&
+       rm -rf sub &&
+       ln -s sub2 sub &&
+       git add sub &&
+       git commit -m ln &&
+       git checkout sub
+ '
 +cat >expect <<\EOF
 +error: Untracked working tree file 'c0.c' would be overwritten by merge.
 +fatal: read-tree failed
 +EOF
 +
 +test_expect_success 'will not overwrite untracked file on unborn branch' '
 +      git reset --hard c0 &&
 +      git rm -fr . &&
 +      git checkout --orphan new &&
 +      cp important c0.c &&
 +      test_must_fail git merge c0 2>out &&
 +      test_cmp out expect &&
 +      test_path_is_missing .git/MERGE_HEAD &&
 +      test_cmp important c0.c
 +'
 +
  test_done