7b2a8052f893fad759294cfa54f55f3aed4cfaad
   1#!/bin/sh
   2#
   3# Copyright (C) 2006 Carl D. Worth <cworth@cworth.org>
   4#
   5
   6test_description='test git clone to cleanup after failure
   7
   8This test covers the fact that if git clone fails, it should remove
   9the directory it created, to avoid the user having to manually
  10remove the directory before attempting a clone again.'
  11
  12. ./test-lib.sh
  13
  14test_expect_success 'clone of non-existent source should fail' '
  15        test_must_fail git clone foo bar
  16'
  17
  18test_expect_success 'failed clone should not leave a directory' '
  19        test_path_is_missing bar
  20'
  21
  22test_expect_success 'create a repo to clone' '
  23        test_create_repo foo
  24'
  25
  26test_expect_success 'create objects in repo for later corruption' '
  27        test_commit -C foo file
  28'
  29
  30# source repository given to git clone should be relative to the
  31# current path not to the target dir
  32test_expect_success 'clone of non-existent (relative to $PWD) source should fail' '
  33        test_must_fail git clone ../foo baz
  34'
  35
  36test_expect_success 'clone should work now that source exists' '
  37        git clone foo bar
  38'
  39
  40test_expect_success 'successful clone must leave the directory' '
  41        test_path_is_dir bar
  42'
  43
  44test_expect_success 'failed clone --separate-git-dir should not leave any directories' '
  45        test_when_finished "rmdir foo/.git/objects.bak" &&
  46        mkdir foo/.git/objects.bak/ &&
  47        test_when_finished "mv foo/.git/objects.bak/* foo/.git/objects/" &&
  48        mv foo/.git/objects/* foo/.git/objects.bak/ &&
  49        test_must_fail git clone --separate-git-dir gitdir foo worktree &&
  50        test_path_is_missing gitdir &&
  51        test_path_is_missing worktree
  52'
  53
  54test_done