From 795c7c0b08fefc7d0f5d0903d8341491350996f0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 28 Nov 2007 13:55:46 -0500 Subject: Add basic cvsimport tests We weren't even testing basic things before, so let's at least try importing and updating a trivial repository, which will catch total breakage. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/t/t9600-cvsimport.sh b/t/t9600-cvsimport.sh new file mode 100755 index 0000000..1ee06bb --- /dev/null +++ b/t/t9600-cvsimport.sh @@ -0,0 +1,99 @@ +#!/bin/sh + +test_description='git-cvsimport basic tests' +. ./test-lib.sh + +if ! ( type cvs && type cvsps ) >/dev/null 2>&1 +then + test_expect_success 'skipping cvsimport tests, cvs/cvsps not found' '' + test_done + exit +fi + +CVSROOT=$(pwd)/cvsroot +export CVSROOT +# for clean cvsps cache +HOME=$(pwd) +export HOME + +test_expect_success 'setup cvsroot' 'cvs init' + +test_expect_success 'setup a cvs module' ' + + mkdir $CVSROOT/module && + cvs co -d module-cvs module && + cd module-cvs && + cat <o_fortuna && +O Fortuna +velut luna +statu variabilis, + +semper crescis +aut decrescis; +vita detestabilis + +nunc obdurat +et tunc curat +ludo mentis aciem, + +egestatem, +potestatem +dissolvit ut glaciem. +EOF + cvs add o_fortuna && + cat <message && +add "O Fortuna" lyrics + +These public domain lyrics make an excellent sample text. +EOF + cvs commit -F message && + cd .. +' + +test_expect_success 'import a trivial module' ' + + git cvsimport -a -z 0 -C module-git module && + git diff module-cvs/o_fortuna module-git/o_fortuna + +' + +test_expect_success 'update cvs module' ' + + cd module-cvs && + cat <o_fortuna && +O Fortune, +like the moon +you are changeable, + +ever waxing +and waning; +hateful life + +first oppresses +and then soothes +as fancy takes it; + +poverty +and power +it melts them like ice. +EOF + cat <message && +translate to English + +My Latin is terrible. +EOF + cvs commit -F message && + cd .. +' + +test_expect_success 'update git module' ' + + cd module-git && + git cvsimport -a -z 0 module && + git merge origin && + cd .. && + git diff module-cvs/o_fortuna module-git/o_fortuna + +' + +test_done -- cgit v0.10.2-6-g49f6 From 9da0dabcd9ff71083b6bbc9878c22b12002400dd Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 28 Nov 2007 13:56:11 -0500 Subject: cvsimport: use rev-parse to support packed refs Previously, if refs were packed, git-cvsimport would assume that particular refs did not exist. This could lead to, for example, overwriting previous 'origin' commits that were packed. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/git-cvsimport.perl b/git-cvsimport.perl index e4bc2b5..a7a7d8f 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -526,18 +526,12 @@ sub is_sha1 { return $s =~ /^[a-f0-9]{40}$/; } -sub get_headref ($$) { - my $name = shift; - my $git_dir = shift; - - my $f = "$git_dir/$remote/$name"; - if (open(my $fh, $f)) { - chomp(my $r = <$fh>); - is_sha1($r) or die "Cannot get head id for $name ($r): $!"; - return $r; - } - die "unable to open $f: $!" unless $! == POSIX::ENOENT; - return undef; +sub get_headref ($) { + my $name = shift; + my $r = `git rev-parse --verify '$name' 2>/dev/null`; + return undef unless $? == 0; + chomp $r; + return $r; } -d $git_tree @@ -697,7 +691,8 @@ my (@old,@new,@skipped,%ignorebranch); $ignorebranch{'#CVSPS_NO_BRANCH'} = 1; sub commit { - if ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) { + if ($branch eq $opt_o && !$index{branch} && + !get_headref("$remote/$branch")) { # looks like an initial commit # use the index primed by git-init $ENV{GIT_INDEX_FILE} = "$git_dir/index"; @@ -721,7 +716,7 @@ sub commit { update_index(@old, @new); @old = @new = (); my $tree = write_tree(); - my $parent = get_headref($last_branch, $git_dir); + my $parent = get_headref("$remote/$last_branch"); print "Parent ID " . ($parent ? $parent : "(empty)") . "\n" if $opt_v; my @commit_args; @@ -732,7 +727,7 @@ sub commit { foreach my $rx (@mergerx) { next unless $logmsg =~ $rx && $1; my $mparent = $1 eq 'HEAD' ? $opt_o : $1; - if (my $sha1 = get_headref($mparent, $git_dir)) { + if (my $sha1 = get_headref("$remote/$mparent")) { push @commit_args, '-p', $mparent; print "Merge parent branch: $mparent\n" if $opt_v; } diff --git a/t/t9600-cvsimport.sh b/t/t9600-cvsimport.sh index 1ee06bb..3338d44 100755 --- a/t/t9600-cvsimport.sh +++ b/t/t9600-cvsimport.sh @@ -57,6 +57,8 @@ test_expect_success 'import a trivial module' ' ' +test_expect_success 'pack refs' 'cd module-git && git gc && cd ..' + test_expect_success 'update cvs module' ' cd module-cvs && -- cgit v0.10.2-6-g49f6 From 0750d751157addde94f28a7933ed4f914a526eb7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 28 Nov 2007 13:56:28 -0500 Subject: cvsimport: miscellaneous packed-ref fixes These were found with a grep for '$git_dir'; they all replace a direct access of "$git_dir/refs/..." with a call to git-rev-parse or git-update-ref. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/git-cvsimport.perl b/git-cvsimport.perl index a7a7d8f..d29b547 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -864,29 +864,27 @@ while () { print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n"; $ancestor = $opt_o; } - if (-f "$git_dir/$remote/$branch") { + if (defined get_headref("$remote/$branch")) { print STDERR "Branch $branch already exists!\n"; $state=11; next; } - unless (open(H,"$git_dir/$remote/$ancestor")) { + my $id = get_headref("$remote/$ancestor"); + if (!$id) { print STDERR "Branch $ancestor does not exist!\n"; $ignorebranch{$branch} = 1; $state=11; next; } - chomp(my $id = ); - close(H); - unless (open(H,"> $git_dir/$remote/$branch")) { - print STDERR "Could not create branch $branch: $!\n"; + + system(qw(git update-ref -m cvsimport), + "$remote/$branch", $id); + if($? != 0) { + print STDERR "Could not create branch $branch\n"; $ignorebranch{$branch} = 1; $state=11; next; } - print H "$id\n" - or die "Could not write branch $branch: $!"; - close(H) - or die "Could not write branch $branch: $!"; } $last_branch = $branch if $branch ne $last_branch; $state = 9; @@ -998,7 +996,7 @@ if ($orig_branch) { $orig_branch = "master"; print "DONE; creating $orig_branch branch\n" if $opt_v; system("git-update-ref", "refs/heads/master", "$remote/$opt_o") - unless -f "$git_dir/refs/heads/master"; + unless defined get_headref('refs/heads/master'); system("git-symbolic-ref", "$remote/HEAD", "$remote/$opt_o") if ($opt_r && $opt_o ne 'HEAD'); system('git-update-ref', 'HEAD', "$orig_branch"); -- cgit v0.10.2-6-g49f6 From fdd7d48d6a09c593a68c983c450443c1e55705e6 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Tue, 27 Nov 2007 13:10:19 +0100 Subject: t7003-filter-branch: Fix test of a failing --msg-filter. The test passed for the wrong reason: If the script given to --msg-filter fails, it is expected that git-filter-branch aborts. But the test forgot to tell the branch name to rewrite, and so git-filter-branch failed due to incorrect usage. Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 2089351..5f60b22 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -114,7 +114,7 @@ test_expect_success 'use index-filter to move into a subdirectory' ' test_expect_success 'stops when msg filter fails' ' old=$(git rev-parse HEAD) && - ! git-filter-branch -f --msg-filter false && + ! git-filter-branch -f --msg-filter false HEAD && test $old = $(git rev-parse HEAD) && rm -rf .git-rewrite ' -- cgit v0.10.2-6-g49f6 From 67d232426b8858b31e54a9b6a5a90916690d1153 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 30 Nov 2007 17:22:12 -0500 Subject: cvsimport: fix usage of cvsimport.module There were two problems: 1. We only look at the config variable if there is no module given on the command line. We checked this by comparing @ARGV == 0. However, at the time of the comparison, we have not yet parsed the dashed options, meaning that "git cvsimport" would read the variable but "git cvsimport -a" would not. This is fixed by simply moving the check after the call to getopt. 2. If the config variable did not exist, we were adding an empty string to @ARGV. The rest of the script, rather than barfing for insufficient input, would then try to import the module '', leading to rather confusing error messages. Based on patch from Emanuele Giaquinta. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/git-cvsimport.perl b/git-cvsimport.perl index d29b547..d565091 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -108,10 +108,6 @@ sub read_repo_config { } } } - if (@ARGV == 0) { - chomp(my $module = `git-repo-config --get cvsimport.module`); - push(@ARGV, $module); - } } my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:"; @@ -119,6 +115,10 @@ read_repo_config($opts); getopts($opts) or usage(); usage if $opt_h; +if (@ARGV == 0) { + chomp(my $module = `git-repo-config --get cvsimport.module`); + push(@ARGV, $module) if $? == 0; +} @ARGV <= 1 or usage("You can't specify more than one CVS module"); if ($opt_d) { diff --git a/t/t9600-cvsimport.sh b/t/t9600-cvsimport.sh index 3338d44..29fee2d 100755 --- a/t/t9600-cvsimport.sh +++ b/t/t9600-cvsimport.sh @@ -98,4 +98,25 @@ test_expect_success 'update git module' ' ' +test_expect_success 'update cvs module' ' + + cd module-cvs && + echo 1 >tick && + cvs add tick && + cvs commit -m 1 + cd .. + +' + +test_expect_success 'cvsimport.module config works' ' + + cd module-git && + git config cvsimport.module module && + git cvsimport -a -z0 && + git merge origin && + cd .. && + git diff module-cvs/tick module-git/tick + +' + test_done -- cgit v0.10.2-6-g49f6 From 10455d2a955a29db1809be139177e4e298771eb0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 30 Nov 2007 11:35:23 +0000 Subject: Replace the word 'update-cache' by 'update-index' everywhere Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index b0a873b..159de30 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -3706,7 +3706,7 @@ should use the `--remove` and `--add` flags respectively. NOTE! A `--remove` flag does 'not' mean that subsequent filenames will necessarily be removed: if the files still exist in your directory structure, the index will be updated with their new status, not -removed. The only thing `--remove` means is that update-cache will be +removed. The only thing `--remove` means is that update-index will be considering a removed file to be a valid thing, and if the file really does not exist any more, it will update the index accordingly. diff --git a/Makefile b/Makefile index e0cfff3..c72d40a 100644 --- a/Makefile +++ b/Makefile @@ -107,7 +107,7 @@ all:: # times (my ext3 doesn't). # # Define USE_STDEV below if you want git to care about the underlying device -# change being considered an inode change from the update-cache perspective. +# change being considered an inode change from the update-index perspective. # # Define ASCIIDOC8 if you want to format documentation with AsciiDoc 8 # diff --git a/configure.ac b/configure.ac index ab516db..8dfe9a0 100644 --- a/configure.ac +++ b/configure.ac @@ -397,7 +397,7 @@ GIT_PARSE_WITH(iconv)) # times (my ext3 doesn't). # # Define USE_STDEV below if you want git to care about the underlying device -# change being considered an inode change from the update-cache perspective. +# change being considered an inode change from the update-index perspective. ## Output files diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh index 7d92ae3..c44b27a 100755 --- a/t/t4000-diff-format.sh +++ b/t/t4000-diff-format.sh @@ -16,7 +16,7 @@ cat path0 >path1 chmod +x path1 test_expect_success \ - 'update-cache --add two files with and without +x.' \ + 'update-index --add two files with and without +x.' \ 'git update-index --add path0 path1' mv path0 path0- diff --git a/t/t4001-diff-rename.sh b/t/t4001-diff-rename.sh index 063e792..2fe50bc 100755 --- a/t/t4001-diff-rename.sh +++ b/t/t4001-diff-rename.sh @@ -27,7 +27,7 @@ Line 15 ' test_expect_success \ - 'update-cache --add a file.' \ + 'update-index --add a file.' \ 'git update-index --add path0' test_expect_success \ diff --git a/t/t4100/t-apply-1.patch b/t/t4100/t-apply-1.patch index de58751..90ab54f 100644 --- a/t/t4100/t-apply-1.patch +++ b/t/t4100/t-apply-1.patch @@ -90,7 +90,7 @@ diff --git a/Documentation/git.txt b/Documentation/git.txt diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile -@@ -30,7 +30,7 @@ PROG= git-update-cache git-diff-files +@@ -30,7 +30,7 @@ PROG= git-update-index git-diff-files git-checkout-cache git-diff-tree git-rev-tree git-ls-files \ git-check-files git-ls-tree git-merge-base git-merge-cache \ git-unpack-file git-export git-diff-cache git-convert-cache \ diff --git a/t/t4100/t-apply-2.patch b/t/t4100/t-apply-2.patch index cfdc808..f5c7d60 100644 --- a/t/t4100/t-apply-2.patch +++ b/t/t4100/t-apply-2.patch @@ -9,7 +9,7 @@ diff --git a/Makefile b/Makefile - git-deltafy-script + git-deltafy-script git-fetch-script - PROG= git-update-cache git-diff-files git-init-db git-write-tree \ + PROG= git-update-index git-diff-files git-init-db git-write-tree \ git-read-tree git-commit-tree git-cat-file git-fsck-cache \ diff --git a/git-pull-script b/git-fetch-script similarity index 87% diff --git a/t/t4100/t-apply-5.patch b/t/t4100/t-apply-5.patch index de11623..5f6ddc1 100644 --- a/t/t4100/t-apply-5.patch +++ b/t/t4100/t-apply-5.patch @@ -200,7 +200,7 @@ diff a/Documentation/git.txt b/Documentation/git.txt diff a/Makefile b/Makefile --- a/Makefile +++ b/Makefile -@@ -30,7 +30,7 @@ PROG= git-update-cache git-diff-files +@@ -30,7 +30,7 @@ PROG= git-update-index git-diff-files git-checkout-cache git-diff-tree git-rev-tree git-ls-files \ git-check-files git-ls-tree git-merge-base git-merge-cache \ git-unpack-file git-export git-diff-cache git-convert-cache \ diff --git a/t/t4100/t-apply-6.patch b/t/t4100/t-apply-6.patch index d975363..a72729a 100644 --- a/t/t4100/t-apply-6.patch +++ b/t/t4100/t-apply-6.patch @@ -8,7 +8,7 @@ diff a/Makefile b/Makefile - git-deltafy-script + git-deltafy-script git-fetch-script - PROG= git-update-cache git-diff-files git-init-db git-write-tree \ + PROG= git-update-index git-diff-files git-init-db git-write-tree \ git-read-tree git-commit-tree git-cat-file git-fsck-cache \ diff a/git-fetch-script b/git-fetch-script --- /dev/null -- cgit v0.10.2-6-g49f6