From afd222967c6abedcf75e28fe0e57cd5644f6c865 Mon Sep 17 00:00:00 2001 From: Josef Weidendorfer Date: Wed, 26 Jul 2006 15:44:08 +0200 Subject: Extend testing git-mv for renaming of subdirectories Signed-off-by: Josef Weidendorfer Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 811a4797a5..d78c56a2eb 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -38,4 +38,25 @@ test_expect_success \ 'git-diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path1/COPYING.+path0/COPYING"' +test_expect_success \ + 'adding another file' \ + 'cp ../../README path0/README && + git-add path0/README && + git-commit -m add2 -a' + +test_expect_success \ + 'moving whole subdirectory' \ + 'git-mv path0 path2' + +test_expect_success \ + 'commiting the change' \ + 'git-commit -m dir-move -a' + +test_expect_success \ + 'checking the commit' \ + 'git-diff-tree -r -M --name-status HEAD^ HEAD | \ + grep -E "^R100.+path0/COPYING.+path2/COPYING" && + git-diff-tree -r -M --name-status HEAD^ HEAD | \ + grep -E "^R100.+path0/README.+path2/README"' + test_done -- cgit v1.2.3 From a1dad607fa5227c844c0f8ab180b811d23792c02 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 19:41:05 +0200 Subject: t7001: add test for git-mv dir1 dir2/ If dir2 already exists, git-mv should move dir1 _into_dir2/. Noticed by Jon Smirl. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index d78c56a2eb..322eaadc73 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -59,4 +59,19 @@ test_expect_success \ git-diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path0/README.+path2/README"' +test_expect_success \ + 'moving whole subdirectory into subdirectory' \ + 'git-mv path2 path1' + +test_expect_success \ + 'commiting the change' \ + 'git-commit -m dir-move -a' + +test_expect_success \ + 'checking the commit' \ + 'git-diff-tree -r -M --name-status HEAD^ HEAD | \ + grep -E "^R100.+path2/COPYING.+path1/path2/COPYING" && + git-diff-tree -r -M --name-status HEAD^ HEAD | \ + grep -E "^R100.+path2/README.+path1/path2/README"' + test_done -- cgit v1.2.3 From ac64a722072bb348476a8a029de9a82073e07fba Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 19:47:54 +0200 Subject: builtin git-mv: support moving directories This fixes the builtin mv for the test which Josef provided, and also fixes moving directories into existing directories, as noted by Jon Smirl. In case the destination exists, fail early (this cannot be overridden by -f). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 322eaadc73..900ca93cde 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -74,4 +74,8 @@ test_expect_success \ git-diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path2/README.+path1/path2/README"' +test_expect_failure \ + 'do not move directory over existing directory' \ + 'mkdir path0 && mkdir path0/path2 && git-mv path2 path0' + test_done -- cgit v1.2.3 From 1d6249e609289940dca179b626fe4ae5433c90cc Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 16 Aug 2006 02:20:32 +0200 Subject: git-mv: succeed even if source is a prefix of destination As noted by Fredrik Kuivinen, without this patch, git-mv fails on git-mv README README-renamed because "README" is a prefix of "README-renamed". Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 900ca93cde..e5e0bb9d51 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -59,6 +59,10 @@ test_expect_success \ git-diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path0/README.+path2/README"' +test_expect_success \ + 'succeed when source is a prefix of destination' \ + 'git-mv path2/COPYING path2/COPYING-renamed' + test_expect_success \ 'moving whole subdirectory into subdirectory' \ 'git-mv path2 path1' -- cgit v1.2.3 From c5203bdf66531c848a2b6cd74f3c02cb18286c55 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 18 Aug 2006 12:42:39 +0200 Subject: git-mv: special case destination "." Since the normalized basename of "." is "", the check for directory failed erroneously. Noticed by Fredrik Kuivinen. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index e5e0bb9d51..b7fcdb390c 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -82,4 +82,8 @@ test_expect_failure \ 'do not move directory over existing directory' \ 'mkdir path0 && mkdir path0/path2 && git-mv path2 path0' +test_expect_success \ + 'move into "."' \ + 'git-mv path1/path2/ .' + test_done -- cgit v1.2.3 From 4fddf5798d8a0eb112c60a05272a2d9407eafc8f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 1 Oct 2006 22:22:07 -0700 Subject: git-mv: invalidate the removed path properly in cache-tree The command updated the cache without invalidating the cache tree entries while removing an existing entry. Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index b7fcdb390c..23a1eff3bb 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -86,4 +86,23 @@ test_expect_success \ 'move into "."' \ 'git-mv path1/path2/ .' +test_expect_success "Michael Cassar's test case" ' + rm -fr .git papers partA && + git init-db && + mkdir -p papers/unsorted papers/all-papers partA && + echo a > papers/unsorted/Thesis.pdf && + echo b > partA/outline.txt && + echo c > papers/unsorted/_another && + git add papers partA && + T1=`git write-tree` && + + git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf && + + T=`git write-tree` && + git ls-tree -r $T | grep partA/outline.txt || { + git ls-tree -r $T + (exit 1) + } +' + test_done -- cgit v1.2.3 From aca085e577688108a2480b96a2f7077424a74e4d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 3 Dec 2006 20:42:47 +0100 Subject: git-mv: search more precisely for source directory in index A move of a directory should find the entries in the index by searching for the name _including_ the slash. Otherwise, the directory can be shadowed by a file when it matches the prefix and is lexicographically smaller, e.g. "ab.c" shadows "ab/". Noticed by Sergey Vlasov. [jc: added Sergey's original reproduction recipe as a test case at the end of t7001.] Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 23a1eff3bb..2f4ff82e14 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -105,4 +105,17 @@ test_expect_success "Michael Cassar's test case" ' } ' +rm -fr papers partA path? + +test_expect_success "Sergey Vlasov's test case" ' + rm -fr .git && + git init-db && + mkdir ab && + date >ab.c && + date >ab/d && + git add ab.c ab && + git commit -m 'initial' && + git mv ab a +' + test_done -- cgit v1.2.3 From 5c94f87e6b17cab5d3b87998d6c907745cb6f5a4 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Fri, 12 Jan 2007 16:01:46 -0500 Subject: use 'init' instead of 'init-db' for shipped docs and tools While 'init-db' still is and probably will always remain a valid git command for obvious backward compatibility reasons, it would be a good idea to move shipped tools and docs to using 'init' instead. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 2f4ff82e14..344033249c 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -88,7 +88,7 @@ test_expect_success \ test_expect_success "Michael Cassar's test case" ' rm -fr .git papers partA && - git init-db && + git init && mkdir -p papers/unsorted papers/all-papers partA && echo a > papers/unsorted/Thesis.pdf && echo b > partA/outline.txt && @@ -109,7 +109,7 @@ rm -fr papers partA path? test_expect_success "Sergey Vlasov's test case" ' rm -fr .git && - git init-db && + git init && mkdir ab && date >ab.c && date >ab/d && -- cgit v1.2.3 From 5be60078c935ed08ee8eb5a32680bdfb6bb5bdf3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2007 22:52:14 -0700 Subject: Rewrite "git-frotz" to "git frotz" This uses the remove-dashes target to replace "git-frotz" to "git frotz". Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 344033249c..8b43fb5a27 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -1,18 +1,18 @@ #!/bin/sh -test_description='git-mv in subdirs' +test_description='git mv in subdirs' . ./test-lib.sh test_expect_success \ 'prepare reference tree' \ 'mkdir path0 path1 && cp ../../COPYING path0/COPYING && - git-add path0/COPYING && + git add path0/COPYING && git-commit -m add -a' test_expect_success \ 'moving the file out of subdirectory' \ - 'cd path0 && git-mv COPYING ../path1/COPYING' + 'cd path0 && git mv COPYING ../path1/COPYING' # in path0 currently test_expect_success \ @@ -21,12 +21,12 @@ test_expect_success \ test_expect_success \ 'checking the commit' \ - 'git-diff-tree -r -M --name-status HEAD^ HEAD | \ + 'git diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path0/COPYING.+path1/COPYING"' test_expect_success \ 'moving the file back into subdirectory' \ - 'cd path0 && git-mv ../path1/COPYING COPYING' + 'cd path0 && git mv ../path1/COPYING COPYING' # in path0 currently test_expect_success \ @@ -35,18 +35,18 @@ test_expect_success \ test_expect_success \ 'checking the commit' \ - 'git-diff-tree -r -M --name-status HEAD^ HEAD | \ + 'git diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path1/COPYING.+path0/COPYING"' test_expect_success \ 'adding another file' \ 'cp ../../README path0/README && - git-add path0/README && + git add path0/README && git-commit -m add2 -a' test_expect_success \ 'moving whole subdirectory' \ - 'git-mv path0 path2' + 'git mv path0 path2' test_expect_success \ 'commiting the change' \ @@ -54,18 +54,18 @@ test_expect_success \ test_expect_success \ 'checking the commit' \ - 'git-diff-tree -r -M --name-status HEAD^ HEAD | \ + 'git diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path0/COPYING.+path2/COPYING" && - git-diff-tree -r -M --name-status HEAD^ HEAD | \ + git diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path0/README.+path2/README"' test_expect_success \ 'succeed when source is a prefix of destination' \ - 'git-mv path2/COPYING path2/COPYING-renamed' + 'git mv path2/COPYING path2/COPYING-renamed' test_expect_success \ 'moving whole subdirectory into subdirectory' \ - 'git-mv path2 path1' + 'git mv path2 path1' test_expect_success \ 'commiting the change' \ @@ -73,18 +73,18 @@ test_expect_success \ test_expect_success \ 'checking the commit' \ - 'git-diff-tree -r -M --name-status HEAD^ HEAD | \ + 'git diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path2/COPYING.+path1/path2/COPYING" && - git-diff-tree -r -M --name-status HEAD^ HEAD | \ + git diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path2/README.+path1/path2/README"' test_expect_failure \ 'do not move directory over existing directory' \ - 'mkdir path0 && mkdir path0/path2 && git-mv path2 path0' + 'mkdir path0 && mkdir path0/path2 && git mv path2 path0' test_expect_success \ 'move into "."' \ - 'git-mv path1/path2/ .' + 'git mv path1/path2/ .' test_expect_success "Michael Cassar's test case" ' rm -fr .git papers partA && -- cgit v1.2.3 From 90ed6c0576156d356aa35ee79aaf85825f9566f6 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sat, 5 Jan 2008 05:06:48 +0100 Subject: t/t7001: avoid unnecessary ERE when using grep As pointed out by Junio, it's unnecessary to use "grep -E" and ".+" when we can just use "grep" and "..*". Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 8b43fb5a27..b730c900b1 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -22,7 +22,7 @@ test_expect_success \ test_expect_success \ 'checking the commit' \ 'git diff-tree -r -M --name-status HEAD^ HEAD | \ - grep -E "^R100.+path0/COPYING.+path1/COPYING"' + grep "^R100..*path0/COPYING..*path1/COPYING"' test_expect_success \ 'moving the file back into subdirectory' \ @@ -36,7 +36,7 @@ test_expect_success \ test_expect_success \ 'checking the commit' \ 'git diff-tree -r -M --name-status HEAD^ HEAD | \ - grep -E "^R100.+path1/COPYING.+path0/COPYING"' + grep "^R100..*path1/COPYING..*path0/COPYING"' test_expect_success \ 'adding another file' \ @@ -55,9 +55,9 @@ test_expect_success \ test_expect_success \ 'checking the commit' \ 'git diff-tree -r -M --name-status HEAD^ HEAD | \ - grep -E "^R100.+path0/COPYING.+path2/COPYING" && + grep "^R100..*path0/COPYING..*path2/COPYING" && git diff-tree -r -M --name-status HEAD^ HEAD | \ - grep -E "^R100.+path0/README.+path2/README"' + grep "^R100..*path0/README..*path2/README"' test_expect_success \ 'succeed when source is a prefix of destination' \ @@ -74,9 +74,9 @@ test_expect_success \ test_expect_success \ 'checking the commit' \ 'git diff-tree -r -M --name-status HEAD^ HEAD | \ - grep -E "^R100.+path2/COPYING.+path1/path2/COPYING" && + grep "^R100..*path2/COPYING..*path1/path2/COPYING" && git diff-tree -r -M --name-status HEAD^ HEAD | \ - grep -E "^R100.+path2/README.+path1/path2/README"' + grep "^R100..*path2/README..*path1/path2/README"' test_expect_failure \ 'do not move directory over existing directory' \ -- cgit v1.2.3 From 41ac414ea2bef81af94474cbef25a38868b4788e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 1 Feb 2008 01:50:53 -0800 Subject: Sane use of test_expect_failure Originally, test_expect_failure was designed to be the opposite of test_expect_success, but this was a bad decision. Most tests run a series of commands that leads to the single command that needs to be tested, like this: test_expect_{success,failure} 'test title' ' setup1 && setup2 && setup3 && what is to be tested ' And expecting a failure exit from the whole sequence misses the point of writing tests. Your setup$N that are supposed to succeed may have failed without even reaching what you are trying to test. The only valid use of test_expect_failure is to check a trivial single command that is expected to fail, which is a minority in tests of Porcelain-ish commands. This large-ish patch rewrites all uses of test_expect_failure to use test_expect_success and rewrites the condition of what is tested, like this: test_expect_success 'test title' ' setup1 && setup2 && setup3 && ! this command should fail ' test_expect_failure is redefined to serve as a reminder that that test *should* succeed but due to a known breakage in git it currently does not pass. So if git-foo command should create a file 'bar' but you discovered a bug that it doesn't, you can write a test like this: test_expect_failure 'git-foo should create bar' ' rm -f bar && git foo && test -f bar ' This construct acts similar to test_expect_success, but instead of reporting "ok/FAIL" like test_expect_success does, the outcome is reported as "FIXED/still broken". Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index b730c900b1..b1243b4163 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -78,9 +78,9 @@ test_expect_success \ git diff-tree -r -M --name-status HEAD^ HEAD | \ grep "^R100..*path2/README..*path1/path2/README"' -test_expect_failure \ +test_expect_success \ 'do not move directory over existing directory' \ - 'mkdir path0 && mkdir path0/path2 && git mv path2 path0' + 'mkdir path0 && mkdir path0/path2 && ! git mv path2 path0' test_expect_success \ 'move into "."' \ -- cgit v1.2.3 From 744dacd3f5045240a304e687f3ef7135398e7865 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 3 Feb 2008 23:59:17 -0800 Subject: builtin-mv: minimum fix to avoid losing files An incorrect command "git mv subdir /outer/space" threw the subdirectory to outside of the repository and then noticed that /outer/space/subdir/ would be outside of the repository. The error checking is backwards. This fixes the issue by being careful about use of the return value of get_pathspec(). Since the implementation already has handcrafted loop to munge each path on the command line, we use prefix_path() instead. Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index b1243b4163..fa382c58da 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -118,4 +118,42 @@ test_expect_success "Sergey Vlasov's test case" ' git mv ab a ' +test_expect_success 'absolute pathname' '( + + rm -fr mine && + mkdir mine && + cd mine && + test_create_repo one && + cd one && + mkdir sub && + >sub/file && + git add sub/file && + + git mv sub "$(pwd)/in" && + ! test -d sub && + test -d in && + git ls-files --error-unmatch in/file + + +)' + +test_expect_success 'absolute pathname outside should fail' '( + + rm -fr mine && + mkdir mine && + cd mine && + out=$(pwd) && + test_create_repo one && + cd one && + mkdir sub && + >sub/file && + git add sub/file && + + ! git mv sub "$out/out" && + test -d sub && + ! test -d ../in && + git ls-files --error-unmatch sub/file + +)' + test_done -- cgit v1.2.3 From d492b31cafe9aa5ce001b1d48815f4c0bb40d01a Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Sat, 12 Jul 2008 17:47:52 +0200 Subject: t/: Use "test_must_fail git" instead of "! git" This patch changes every occurrence of "! git" -- with the meaning that a git call has to gracefully fail -- into "test_must_fail git". This is useful to - make sure the test does not fail because of a signal, e.g. SIGSEGV, and - advertise the use of "test_must_fail" for new tests. Signed-off-by: Stephan Beyer Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index fa382c58da..336cfaa1c5 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -80,7 +80,7 @@ test_expect_success \ test_expect_success \ 'do not move directory over existing directory' \ - 'mkdir path0 && mkdir path0/path2 && ! git mv path2 path0' + 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0' test_expect_success \ 'move into "."' \ @@ -149,7 +149,7 @@ test_expect_success 'absolute pathname outside should fail' '( >sub/file && git add sub/file && - ! git mv sub "$out/out" && + test_must_fail git mv sub "$out/out" && test -d sub && ! test -d ../in && git ls-files --error-unmatch sub/file -- cgit v1.2.3 From 81dc2307d0ad87a4da2e753a9d1b5586d6456eed Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 21 Jul 2008 02:25:56 +0200 Subject: git-mv: Keep moved index entries inact The rewrite of git-mv from a shell script to a builtin was perhaps a little too straightforward: the git add and git rm queues were emulated directly, which resulted in a rather complicated code and caused an inconsistent behaviour when moving dirty index entries; git mv would update the entry based on working tree state, except in case of overwrites, where the new entry would still have sha1 of the old file. This patch introduces rename_index_entry_at() into the index toolkit, which will rename an entry while removing any entries the new entry might render duplicate. This is then used in git mv instead of all the file queues, resulting in a major simplification of the code and an inevitable change in git mv -n output format. Also the code used to refuse renaming overwriting symlink with a regular file and vice versa; there is no need for that. A few new tests have been added to the testsuite to reflect this change. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 336cfaa1c5..b0fa407825 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -156,4 +156,56 @@ test_expect_success 'absolute pathname outside should fail' '( )' +test_expect_success 'git mv should not change sha1 of moved cache entry' ' + + rm -fr .git && + git init && + echo 1 >dirty && + git add dirty && + entry="$(git ls-files --stage dirty | cut -f 1)" + git mv dirty dirty2 && + [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] && + echo 2 >dirty2 && + git mv dirty2 dirty && + [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ] + +' + +rm -f dirty dirty2 + +test_expect_success 'git mv should overwrite symlink to a file' ' + + rm -fr .git && + git init && + echo 1 >moved && + ln -s moved symlink && + git add moved symlink && + test_must_fail git mv moved symlink && + git mv -f moved symlink && + ! test -e moved && + test -f symlink && + test "$(cat symlink)" = 1 && + git diff-files --quiet + +' + +rm -f moved symlink + +test_expect_success 'git mv should overwrite file with a symlink' ' + + rm -fr .git && + git init && + echo 1 >moved && + ln -s moved symlink && + git add moved symlink && + test_must_fail git mv symlink moved && + git mv -f symlink moved && + ! test -e symlink && + test -h moved && + git diff-files --quiet + +' + +rm -f moved symlink + test_done -- cgit v1.2.3 From 65c35b2256ecbfaebcf04559fe6070807646afff Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 28 Jul 2008 22:27:39 -0700 Subject: t7001: fix "git mv" test The test assumed that we can keep the cached stat information fresh across rename(2); many filesystems however update st_ctime (and POSIX allows them to do so), and that assumption does not hold. We can explicitly refresh the index for the purpose of these tests. The only thing we are interested in is the staged contents and the mode bits are preserved across "git mv". Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index b0fa407825..910a28c7e2 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -185,6 +185,7 @@ test_expect_success 'git mv should overwrite symlink to a file' ' ! test -e moved && test -f symlink && test "$(cat symlink)" = 1 && + git update-index --refresh && git diff-files --quiet ' @@ -202,6 +203,7 @@ test_expect_success 'git mv should overwrite file with a symlink' ' git mv -f symlink moved && ! test -e symlink && test -h moved && + git update-index --refresh && git diff-files --quiet ' -- cgit v1.2.3 From bfdbee98109c5ad2dbbc392e7eed1ae688acc039 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 8 Aug 2008 02:26:28 -0700 Subject: tests: use $TEST_DIRECTORY to refer to the t/ directory Many test scripts assumed that they will start in a 'trash' subdirectory that is a single level down from the t/ directory, and referred to their test vector files by asking for files like "../t9999/expect". This will break if we move the 'trash' subdirectory elsewhere. To solve this, we earlier introduced "$TEST_DIRECTORY" so that they can refer to t/ directory reliably. This finally makes all the tests use it to refer to the outside environment. With this patch, and a one-liner not included here (because it would contradict with what Dscho really wants to do): | diff --git a/t/test-lib.sh b/t/test-lib.sh | index 70ea7e0..60e69e4 100644 | --- a/t/test-lib.sh | +++ b/t/test-lib.sh | @@ -485,7 +485,7 @@ fi | . ../GIT-BUILD-OPTIONS | | # Test repository | -test="trash directory" | +test="trash directory/another level/yet another" | rm -fr "$test" || { | trap - exit | echo >&5 "FATAL: Cannot prepare test area" all the tests still pass, but we would want extra sets of eyeballs on this type of change to really make sure. [jc: with help from Stephan Beyer on http-push tests I do not run myself; credits for locating silly quoting errors go to Olivier Marin.] Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 910a28c7e2..78167980b3 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -6,7 +6,7 @@ test_description='git mv in subdirs' test_expect_success \ 'prepare reference tree' \ 'mkdir path0 path1 && - cp ../../COPYING path0/COPYING && + cp "$TEST_DIRECTORY"/../COPYING path0/COPYING && git add path0/COPYING && git-commit -m add -a' @@ -40,7 +40,7 @@ test_expect_success \ test_expect_success \ 'adding another file' \ - 'cp ../../README path0/README && + 'cp "$TEST_DIRECTORY"/../README path0/README && git add path0/README && git-commit -m add2 -a' -- cgit v1.2.3 From d592b3157f70c9dac6288b28c46a64826c0abd18 Mon Sep 17 00:00:00 2001 From: Nanako Shiraishi Date: Wed, 3 Sep 2008 17:59:31 +0900 Subject: tests: use "git xyzzy" form (t7000 - t7199) Converts tests between t7001-t7103. Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 910a28c7e2..66bb1264ff 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -8,7 +8,7 @@ test_expect_success \ 'mkdir path0 path1 && cp ../../COPYING path0/COPYING && git add path0/COPYING && - git-commit -m add -a' + git commit -m add -a' test_expect_success \ 'moving the file out of subdirectory' \ @@ -17,7 +17,7 @@ test_expect_success \ # in path0 currently test_expect_success \ 'commiting the change' \ - 'cd .. && git-commit -m move-out -a' + 'cd .. && git commit -m move-out -a' test_expect_success \ 'checking the commit' \ @@ -31,7 +31,7 @@ test_expect_success \ # in path0 currently test_expect_success \ 'commiting the change' \ - 'cd .. && git-commit -m move-in -a' + 'cd .. && git commit -m move-in -a' test_expect_success \ 'checking the commit' \ @@ -42,7 +42,7 @@ test_expect_success \ 'adding another file' \ 'cp ../../README path0/README && git add path0/README && - git-commit -m add2 -a' + git commit -m add2 -a' test_expect_success \ 'moving whole subdirectory' \ @@ -50,7 +50,7 @@ test_expect_success \ test_expect_success \ 'commiting the change' \ - 'git-commit -m dir-move -a' + 'git commit -m dir-move -a' test_expect_success \ 'checking the commit' \ @@ -69,7 +69,7 @@ test_expect_success \ test_expect_success \ 'commiting the change' \ - 'git-commit -m dir-move -a' + 'git commit -m dir-move -a' test_expect_success \ 'checking the commit' \ -- cgit v1.2.3 From 3772923f1429f2888074e698c36c071b864effe3 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Wed, 14 Jan 2009 18:03:21 +0100 Subject: add test cases for "git mv -k" Add test cases for ignoring nonexisting and untracked files using the -k option to "git mv". There is one known breakage related to multiple untracked files specfied as consecutive arguments. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 66bb1264ff..fddcdde6eb 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -38,6 +38,31 @@ test_expect_success \ 'git diff-tree -r -M --name-status HEAD^ HEAD | \ grep "^R100..*path1/COPYING..*path0/COPYING"' +test_expect_success \ + 'checking -k on non-existing file' \ + 'git mv -k idontexist path0' + +test_expect_success \ + 'checking -k on untracked file' \ + 'touch untracked1 && + git mv -k untracked1 path0 && + test -f untracked1 && + test ! -f path0/untracked1' + +test_expect_failure \ + 'checking -k on multiple untracked files' \ + 'touch untracked2 && + git mv -k untracked1 untracked2 path0 && + test -f untracked1 && + test -f untracked2 && + test ! -f path0/untracked1 + test ! -f path0/untracked2' + +# clean up the mess in case bad things happen +rm -f idontexist untracked1 untracked2 \ + path0/idontexist path0/untracked1 path0/untracked2 \ + .git/index.lock + test_expect_success \ 'adding another file' \ 'cp ../../README path0/README && -- cgit v1.2.3 From be17262d13f5f3df5ee9635b11dad180613e9cbd Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Wed, 14 Jan 2009 18:03:22 +0100 Subject: fix handling of multiple untracked files for git mv -k The "-k" option to "git mv" should allow specifying multiple untracked files. Currently, multiple untracked files raise an assertion if they appear consecutively as arguments. Fix this by decrementing the loop index after removing one entry from the array of arguments. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index fddcdde6eb..19493c8052 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -49,7 +49,7 @@ test_expect_success \ test -f untracked1 && test ! -f path0/untracked1' -test_expect_failure \ +test_expect_success \ 'checking -k on multiple untracked files' \ 'touch untracked2 && git mv -k untracked1 untracked2 path0 && -- cgit v1.2.3 From 720ec6b870ba913affd0f6c01d5a61b9b2c5aadb Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Wed, 4 Feb 2009 10:32:06 +0100 Subject: Missing && in t/t7001.sh. Without this, the exit status is only the one of the last line. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 19493c8052..539effe694 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -55,7 +55,7 @@ test_expect_success \ git mv -k untracked1 untracked2 path0 && test -f untracked1 && test -f untracked2 && - test ! -f path0/untracked1 + test ! -f path0/untracked1 && test ! -f path0/untracked2' # clean up the mess in case bad things happen -- cgit v1.2.3 From c8ba6b1b199bf00f227e8fdad4adb5a2147c8160 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Wed, 4 Feb 2009 10:32:07 +0100 Subject: Add a testcase for "git mv -f" on untracked files. This currently fails with: git: builtin-mv.c:217: cmd_mv: Assertion `pos >= 0' failed. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 539effe694..ef7e56ed63 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -58,6 +58,14 @@ test_expect_success \ test ! -f path0/untracked1 && test ! -f path0/untracked2' +test_expect_failure \ + 'checking -f on untracked file with existing target' \ + 'touch path0/untracked1 && + git mv -f untracked1 path0 + test ! -f .git/index.lock && + test -f untracked1 && + test -f path0/untracked1' + # clean up the mess in case bad things happen rm -f idontexist untracked1 untracked2 \ path0/idontexist path0/untracked1 path0/untracked2 \ -- cgit v1.2.3 From 5aed3c6ab834367292bd7a9b0894177a07afd910 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Wed, 4 Feb 2009 10:32:08 +0100 Subject: builtin-mv.c: check for unversionned files before looking at the destination. The previous code was failing in the case where one moves an unversionned file to an existing destination, with mv -f: the "existing destination" was checked first, and the error was cancelled by the force flag. We now check the unrecoverable error first, which fixes the bug. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index ef7e56ed63..d2ec550af6 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -58,7 +58,7 @@ test_expect_success \ test ! -f path0/untracked1 && test ! -f path0/untracked2' -test_expect_failure \ +test_expect_success \ 'checking -f on untracked file with existing target' \ 'touch path0/untracked1 && git mv -f untracked1 path0 -- cgit v1.2.3 From 704a3143d5ba0709727430154ef3dad600aad4de Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Wed, 4 Mar 2009 22:38:24 +0100 Subject: Use prerequisite tags to skip tests that depend on symbolic links Many tests depend on that symbolic links work. This introduces a check that sets the prerequisite tag SYMLINKS if the file system supports symbolic links. Since so many tests have to check for this prerequisite, we do the check in test-lib.sh, so that we don't need to repeat the test in many scripts. To check for 'ln -s' failures, you can use a FAT partition on Linux: $ mkdosfs -C git-on-fat 1000000 $ sudo mount -o loop,uid=j6t,gid=users,shortname=winnt git-on-fat /mnt Clone git to /mnt and $ GIT_SKIP_TESTS='t0001.1[34] t0010 t1301 t403[34] t4129.[47] t5701.7 t7701.3 t9100 t9101.26 t9119 t9124.[67] t9200.10 t9600.6' \ make test (These additionally skipped tests depend on POSIX permissions that FAT on Linux does not provide.) Signed-off-by: Johannes Sixt --- t/t7001-mv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 8fb3a56838..10b8f8c44b 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -206,7 +206,7 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' ' rm -f dirty dirty2 -test_expect_success 'git mv should overwrite symlink to a file' ' +test_expect_success SYMLINKS 'git mv should overwrite symlink to a file' ' rm -fr .git && git init && @@ -225,7 +225,7 @@ test_expect_success 'git mv should overwrite symlink to a file' ' rm -f moved symlink -test_expect_success 'git mv should overwrite file with a symlink' ' +test_expect_success SYMLINKS 'git mv should overwrite file with a symlink' ' rm -fr .git && git init && -- cgit v1.2.3 From af82559b435aa2a18f38a4f47a93729c8dc543d3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 22 Jan 2010 14:17:06 -0800 Subject: git-mv: fix moving more than one source to a single destination The code used as if return value from basename(3) were stable, but often the function is implemented to return a pointer to a static storage internal to it. Because basename(3) is also allowed to modify its input parameter in place, casting constness away from the strings we obtained from the caller and giving them to basename is a no-no. Reported, and initial fix and test supplied by David Rydh. Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 10b8f8c44b..65a35d94a0 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -189,6 +189,18 @@ test_expect_success 'absolute pathname outside should fail' '( )' +test_expect_success 'git mv to move multiple sources into a directory' ' + rm -fr .git && git init && + mkdir dir other && + >dir/a.txt && + >dir/b.txt && + git add dir/?.txt && + git mv dir/a.txt dir/b.txt other && + git ls-files >actual && + { echo other/a.txt; echo other/b.txt; } >expect && + test_cmp expect actual +' + test_expect_success 'git mv should not change sha1 of moved cache entry' ' rm -fr .git && -- cgit v1.2.3 From a2b1e53b94e99fa88394b1317be478d5c5d864dc Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sun, 3 Oct 2010 14:00:10 -0600 Subject: t7001 (mv): add missing && MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also, prefix an expected-to-fail git mv command with 'test_must_fail'. Acked-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jonathan Nieder Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 65a35d94a0..624e6d25de 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -61,7 +61,7 @@ test_expect_success \ test_expect_success \ 'checking -f on untracked file with existing target' \ 'touch path0/untracked1 && - git mv -f untracked1 path0 + test_must_fail git mv -f untracked1 path0 && test ! -f .git/index.lock && test -f untracked1 && test -f path0/untracked1' -- cgit v1.2.3 From 2dec68cf8fec760930c3bc9d13beb17e381d70a3 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sun, 31 Oct 2010 02:30:58 -0500 Subject: tests: add missing &&, batch 2 Same rules as before: this patch only adds " &&" to the end of some lines in the test suite. Intended to be applied on top of or squashed with the last batch if they look okay. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7001-mv.sh') diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 624e6d25de..a845b154e4 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -207,7 +207,7 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' ' git init && echo 1 >dirty && git add dirty && - entry="$(git ls-files --stage dirty | cut -f 1)" + entry="$(git ls-files --stage dirty | cut -f 1)" && git mv dirty dirty2 && [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] && echo 2 >dirty2 && -- cgit v1.2.3