From 41ff7a1076e9282535f77ddfb4e23a95354009fd Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 17 Feb 2006 13:33:24 -0800 Subject: Trap exit to clean up created directory if clone fails. Signed-off-by: Carl Worth Signed-off-by: Junio C Hamano diff --git a/git-clone.sh b/git-clone.sh index e192b08..d184ceb 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -118,6 +118,7 @@ dir="$2" [ -e "$dir" ] && echo "$dir already exists." && usage mkdir -p "$dir" && D=$(cd "$dir" && pwd) && +trap 'err=$?; rm -r $D; exit $err' exit case "$bare" in yes) GIT_DIR="$D" ;; *) GIT_DIR="$D/.git" ;; @@ -255,3 +256,6 @@ Pull: $head_points_at:$origin" && git checkout esac fi + +trap - exit + -- cgit v0.10.2-6-g49f6 From eedf8f97e58bbf4717705900379f2d63134047f9 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 17 Feb 2006 13:33:26 -0800 Subject: Abstract test_create_repo out for use in tests. Signed-off-by: Carl Worth Signed-off-by: Junio C Hamano diff --git a/t/test-lib.sh b/t/test-lib.sh index 7a58a86..66f62b9 100755 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -149,6 +149,21 @@ test_expect_code () { fi } +# Most tests can use the created repository, but some amy need to create more. +# Usage: test_create_repo +test_create_repo () { + test "$#" = 1 || + error "bug in the test script: not 1 parameter to test-create-repo" + owd=`pwd` + repo="$1" + mkdir "$repo" + cd "$repo" || error "Cannot setup test environment" + "$GIT_EXEC_PATH/git" init-db --template=$GIT_EXEC_PATH/templates/blt/ 2>/dev/null || + error "cannot run git init-db -- have you built things yet?" + mv .git/hooks .git/hooks-disabled + cd "$owd" +} + test_done () { trap - exit case "$test_failure" in @@ -196,9 +211,5 @@ test -d ../templates/blt || { # Test repository test=trash rm -fr "$test" -mkdir "$test" -cd "$test" || error "Cannot setup test environment" -"$GIT_EXEC_PATH/git" init-db --template=../../templates/blt/ 2>/dev/null || -error "cannot run git init-db -- have you built things yet?" - -mv .git/hooks .git/hooks-disabled +test_create_repo $test +cd "$test" -- cgit v0.10.2-6-g49f6 From b5b16990f8b074bd0481ced047b8f8bf66eee6dc Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 17 Feb 2006 16:14:52 -0800 Subject: Prevent git-upload-pack segfault if object cannot be found Signed-off-by: Carl Worth Signed-off-by: Junio C Hamano diff --git a/sha1_file.c b/sha1_file.c index 3d11a9b..f08b1d6 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -551,8 +551,10 @@ static void prepare_packed_git_one(char *objdir, int local) sprintf(path, "%s/pack", objdir); len = strlen(path); dir = opendir(path); - if (!dir) + if (!dir) { + fprintf(stderr, "unable to open object pack directory: %s: %s\n", path, strerror(errno)); return; + } path[len++] = '/'; while ((de = readdir(dir)) != NULL) { int namelen = strlen(de->d_name); diff --git a/upload-pack.c b/upload-pack.c index d198055..3606529 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -216,6 +216,9 @@ static int send_ref(const char *refname, const unsigned char *sha1) static char *capabilities = "multi_ack"; struct object *o = parse_object(sha1); + if (!o) + die("git-upload-pack: cannot find object %s:", sha1_to_hex(sha1)); + if (capabilities) packet_write(1, "%s %s%c%s\n", sha1_to_hex(sha1), refname, 0, capabilities); -- cgit v0.10.2-6-g49f6 From 44de0da4f908b6600647673e1236b0ca504a9c15 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 18 Feb 2006 02:10:53 +0100 Subject: git-rev-parse: Fix --short= option parsing Signed-off-by: Jonas Fonseca diff --git a/rev-parse.c b/rev-parse.c index b82f294..70a8271 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -225,12 +225,12 @@ int main(int argc, char **argv) continue; } if (!strcmp(arg, "--short") || - !strncmp(arg, "--short=", 9)) { + !strncmp(arg, "--short=", 8)) { filter &= ~(DO_FLAGS|DO_NOREV); verify = 1; abbrev = DEFAULT_ABBREV; - if (arg[8] == '=') - abbrev = strtoul(arg + 9, NULL, 10); + if (arg[7] == '=') + abbrev = strtoul(arg + 8, NULL, 10); if (abbrev < MINIMUM_ABBREV) abbrev = MINIMUM_ABBREV; else if (40 <= abbrev) -- cgit v0.10.2-6-g49f6 From 735d80b3bf1be9513d030e61af1ef6512cec015a Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 18 Feb 2006 02:11:36 +0100 Subject: Document --short and --git-dir in git-rev-parse(1) Signed-off-by: Jonas Fonseca diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt index d638bfc..1662e06 100644 --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@ -77,6 +77,14 @@ OPTIONS path of the top-level directory relative to the current directory (typically a sequence of "../", or an empty string). +--git-dir:: + Show `$GIT_DIR` if defined else show the path to the .git directory. + +--short, short=number:: + Instead of outputting the full SHA1 values of object names try to + abbriviate them to a shorter unique name. When no length is specified + 7 is used. The minimum length is 4. + --since=datestring, --after=datestring:: Parses the date string, and outputs corresponding --max-age= parameter for git-rev-list command. -- cgit v0.10.2-6-g49f6 From 772d8a3b63ff669c285edb8aff0c63b609614933 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 17 Feb 2006 02:26:16 -0500 Subject: Make git-reset delete empty directories When git-reset --hard is used and a subdirectory becomes empty (as it contains no tracked files in the target tree) the empty subdirectory should be removed. This matches the behavior of git-checkout-index and git-read-tree -m which would not have created the subdirectory or would have deleted it when updating the working directory. Subdirectories which are not empty will be left behind. This may happen if the subdirectory still contains object files from the user's build process (for example). [jc: simplified the logic a bit, while keeping the test script.] diff --git a/git-reset.sh b/git-reset.sh index fe53fc8..6cb073c 100755 --- a/git-reset.sh +++ b/git-reset.sh @@ -88,6 +88,9 @@ case "$reset_type" in # it is ok if this fails -- it may already # have been culled by checkout-index. unlink $_; + while (s|/[^/]*$||) { + rmdir($_) or last; + } } } ' $tmp-exists diff --git a/t/t7101-reset.sh b/t/t7101-reset.sh new file mode 100755 index 0000000..a919140 --- /dev/null +++ b/t/t7101-reset.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# +# Copyright (c) 2006 Shawn Pearce +# + +test_description='git-reset should cull empty subdirs' +. ./test-lib.sh + +test_expect_success \ + 'creating initial files' \ + 'mkdir path0 && + cp ../../COPYING path0/COPYING && + git-add path0/COPYING && + git-commit -m add -a' + +test_expect_success \ + 'creating second files' \ + 'mkdir path1 && + mkdir path1/path2 && + cp ../../COPYING path1/path2/COPYING && + cp ../../COPYING path1/COPYING && + cp ../../COPYING COPYING && + cp ../../COPYING path0/COPYING-TOO && + git-add path1/path2/COPYING && + git-add path1/COPYING && + git-add COPYING && + git-add path0/COPYING-TOO && + git-commit -m change -a' + +test_expect_success \ + 'resetting tree HEAD^' \ + 'git-reset --hard HEAD^' + +test_expect_success \ + 'checking initial files exist after rewind' \ + 'test -d path0 && + test -f path0/COPYING' + +test_expect_failure \ + 'checking lack of path1/path2/COPYING' \ + 'test -f path1/path2/COPYING' + +test_expect_failure \ + 'checking lack of path1/COPYING' \ + 'test -f path1/COPYING' + +test_expect_failure \ + 'checking lack of COPYING' \ + 'test -f COPYING' + +test_expect_failure \ + 'checking checking lack of path1/COPYING-TOO' \ + 'test -f path0/COPYING-TOO' + +test_expect_failure \ + 'checking lack of path1/path2' \ + 'test -d path1/path2' + +test_expect_failure \ + 'checking lack of path1' \ + 'test -d path1' + +test_done -- cgit v0.10.2-6-g49f6 From 3ff903bfb9e34a02f681f1c95ef7aa3ce4d54d2a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 18 Feb 2006 03:49:38 -0800 Subject: archimport: remove files from the index before adding/updating This fixes a bug when importing where a directory gets removed/renamed but is immediately replaced by a file of the same name in the same changeset. This fix only applies to the accurate (default) strategy the moment. This patch should also fix the fast strategy if/when it is updated to handle the cases that would've triggered this bug. This bug was originally found in git-svn, but I remembered I did the same thing with archimport as well. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano diff --git a/git-archimport.perl b/git-archimport.perl index 841738d..6792624 100755 --- a/git-archimport.perl +++ b/git-archimport.perl @@ -346,12 +346,10 @@ sub process_patchset_accurate { } # update the index with all the changes we got + system('git-diff-files --name-only -z | '. + 'git-update-index --remove -z --stdin') == 0 or die "$! $?\n"; system('git-ls-files --others -z | '. 'git-update-index --add -z --stdin') == 0 or die "$! $?\n"; - system('git-ls-files --deleted -z | '. - 'git-update-index --remove -z --stdin') == 0 or die "$! $?\n"; - system('git-ls-files -z | '. - 'git-update-index -z --stdin') == 0 or die "$! $?\n"; return 1; } @@ -416,22 +414,14 @@ sub process_patchset_fast { # imports don't give us good info # on added files. Shame on them if ($ps->{type} eq 'i' || $ps->{type} eq 't') { - system('git-ls-files --others -z | '. - 'git-update-index --add -z --stdin') == 0 or die "$! $?\n"; system('git-ls-files --deleted -z | '. 'git-update-index --remove -z --stdin') == 0 or die "$! $?\n"; + system('git-ls-files --others -z | '. + 'git-update-index --add -z --stdin') == 0 or die "$! $?\n"; } # TODO: handle removed_directories and renamed_directories: - - if (my $add = $ps->{new_files}) { - while (@$add) { - my @slice = splice(@$add, 0, 100); - system('git-update-index','--add','--',@slice) == 0 or - die "Error in git-update-index --add: $! $?\n"; - } - } - + if (my $del = $ps->{removed_files}) { unlink @$del; while (@$del) { @@ -462,6 +452,14 @@ sub process_patchset_fast { } } + if (my $add = $ps->{new_files}) { + while (@$add) { + my @slice = splice(@$add, 0, 100); + system('git-update-index','--add','--',@slice) == 0 or + die "Error in git-update-index --add: $! $?\n"; + } + } + if (my $mod = $ps->{modified_files}) { while (@$mod) { my @slice = splice(@$mod, 0, 100); -- cgit v0.10.2-6-g49f6 From 39ba7d54649b35c943b026b54bff40cfa0153f3e Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 18 Feb 2006 21:44:20 +0100 Subject: Fix retries in git-cvsimport Fixed a couple of bugs in recovering from broken connections: The _line() method now returns undef correctly when the connection is broken instead of falling off the function and returning garbage. Retries are now reported to stderr and the eventual partially downloaded file is discarded instead of being appended to. The "Server gone away" test has been removed, because it was reachable only if the garbage return bug bit. Signed-off-by: Martin Mares Signed-off-by: Junio C Hamano diff --git a/git-cvsimport.perl b/git-cvsimport.perl index 00fc3ba..24f9834 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -361,6 +361,7 @@ sub _line { } } } + return undef; } sub file { my($self,$fn,$rev) = @_; @@ -372,19 +373,15 @@ sub file { $self->_file($fn,$rev) and $res = $self->_line($fh); if (!defined $res) { - # retry + print STDERR "Server has gone away while fetching $fn $rev, retrying...\n"; + truncate $fh, 0; $self->conn(); - $self->_file($fn,$rev) - or die "No file command send\n"; + $self->_file($fn,$rev) or die "No file command send"; $res = $self->_line($fh); - die "No input: $fn $rev\n" unless defined $res; + die "Retry failed" unless defined $res; } close ($fh); - if ($res eq '') { - die "Looks like the server has gone away while fetching $fn $rev -- exiting!"; - } - return ($name, $res); } -- cgit v0.10.2-6-g49f6