Merge branch 'cb/http-test'
authorJunio C Hamano <gitster@pobox.com>
Sun, 2 Mar 2008 23:11:23 +0000 (15:11 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 2 Mar 2008 23:11:23 +0000 (15:11 -0800)
* cb/http-test:
  http-push: add regression tests
  http-push: push <remote> :<branch> deletes remote branch

1  2 
http-push.c
t/test-lib.sh

diff --combined http-push.c
@@@ -664,7 -664,8 +664,7 @@@ static void release_request(struct tran
                close(request->local_fileno);
        if (request->local_stream)
                fclose(request->local_stream);
 -      if (request->url != NULL)
 -              free(request->url);
 +      free(request->url);
        free(request);
  }
  
@@@ -1282,8 -1283,10 +1282,8 @@@ static struct remote_lock *lock_remote(
        strbuf_release(&in_buffer);
  
        if (lock->token == NULL || lock->timeout <= 0) {
 -              if (lock->token != NULL)
 -                      free(lock->token);
 -              if (lock->owner != NULL)
 -                      free(lock->owner);
 +              free(lock->token);
 +              free(lock->owner);
                free(url);
                free(lock);
                lock = NULL;
@@@ -1341,7 -1344,8 +1341,7 @@@ static int unlock_remote(struct remote_
                        prev->next = prev->next->next;
        }
  
 -      if (lock->owner != NULL)
 -              free(lock->owner);
 +      free(lock->owner);
        free(lock->url);
        free(lock->token);
        free(lock);
@@@ -2031,7 -2035,8 +2031,7 @@@ static void fetch_symref(const char *pa
        }
        free(url);
  
 -      if (*symref != NULL)
 -              free(*symref);
 +      free(*symref);
        *symref = NULL;
        hashclr(sha1);
  
@@@ -2133,6 -2138,8 +2133,8 @@@ static int delete_remote_branch(char *p
  
        /* Send delete request */
        fprintf(stderr, "Removing remote branch '%s'\n", remote_ref->name);
+       if (dry_run)
+               return 0;
        url = xmalloc(strlen(remote->url) + strlen(remote_ref->name) + 1);
        sprintf(url, "%s%s", remote->url, remote_ref->name);
        slot = get_active_slot();
@@@ -2306,6 -2313,16 +2308,16 @@@ int main(int argc, char **argv
  
                if (!ref->peer_ref)
                        continue;
+               if (is_zero_sha1(ref->peer_ref->new_sha1)) {
+                       if (delete_remote_branch(ref->name, 1) == -1) {
+                               error("Could not remove %s", ref->name);
+                               rc = -4;
+                       }
+                       new_refs++;
+                       continue;
+               }
                if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
                        if (push_verbosely || 1)
                                fprintf(stderr, "'%s': up-to-date\n", ref->name);
                        }
                }
                hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
-               if (is_zero_sha1(ref->new_sha1)) {
-                       error("cannot happen anymore");
-                       rc = -3;
-                       continue;
-               }
                new_refs++;
                strcpy(old_hex, sha1_to_hex(ref->old_sha1));
                new_hex = sha1_to_hex(ref->new_sha1);
        }
  
   cleanup:
 -      if (rewritten_url)
 -              free(rewritten_url);
 +      free(rewritten_url);
        if (info_ref_lock)
                unlock_remote(info_ref_lock);
        free(remote);
diff --combined t/test-lib.sh
@@@ -80,7 -80,7 +80,7 @@@ d
        -q|--q|--qu|--qui|--quie|--quiet)
                quiet=t; shift ;;
        --no-color)
-           color=; shift ;;
+               color=; shift ;;
        --no-python)
                # noop now...
                shift ;;
@@@ -142,7 -142,12 +142,12 @@@ test_count=
  test_fixed=0
  test_broken=0
  
- trap 'echo >&5 "FATAL: Unexpected exit with code $?"; exit 1' exit
+ die () {
+       echo >&5 "FATAL: Unexpected exit with code $?"
+       exit 1
+ }
+ trap 'die' exit
  
  test_tick () {
        if test -z "${test_tick+set}"
@@@ -270,23 -275,6 +275,23 @@@ test_expect_code () 
        echo >&3 ""
  }
  
 +# This is not among top-level (test_expect_success | test_expect_failure)
 +# but is a prefix that can be used in the test script, like:
 +#
 +#     test_expect_success 'complain and die' '
 +#           do something &&
 +#           do something else &&
 +#         test_must_fail git checkout ../outerspace
 +#     '
 +#
 +# Writing this as "! git checkout ../outerspace" is wrong, because
 +# the failure could be due to a segv.  We want a controlled failure.
 +
 +test_must_fail () {
 +      "$@"
 +      test $? -gt 0 -a $? -le 128
 +}
 +
  # Most tests can use the created repository, but some may need to create more.
  # Usage: test_create_repo <directory>
  test_create_repo () {
@@@ -359,8 -347,6 +364,8 @@@ if ! test -x ../test-chmtime; the
        exit 1
  fi
  
 +. ../GIT-BUILD-OPTIONS
 +
  # Test repository
  test=trash
  rm -fr "$test"