t / t2060-switch.shon commit doc: promote "git restore" (80f537f)
   1#!/bin/sh
   2
   3test_description='switch basic functionality'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        test_commit first &&
   9        git branch first-branch &&
  10        test_commit second &&
  11        test_commit third &&
  12        git remote add origin nohost:/nopath &&
  13        git update-ref refs/remotes/origin/foo first-branch
  14'
  15
  16test_expect_success 'switch branch no arguments' '
  17        test_must_fail git switch
  18'
  19
  20test_expect_success 'switch branch' '
  21        git switch first-branch &&
  22        test_path_is_missing second.t
  23'
  24
  25test_expect_success 'switch and detach' '
  26        test_when_finished git switch master &&
  27        test_must_fail git switch master^{commit} &&
  28        git switch --detach master^{commit} &&
  29        test_must_fail git symbolic-ref HEAD
  30'
  31
  32test_expect_success 'switch and detach current branch' '
  33        test_when_finished git switch master &&
  34        git switch master &&
  35        git switch --detach &&
  36        test_must_fail git symbolic-ref HEAD
  37'
  38
  39test_expect_success 'switch and create branch' '
  40        test_when_finished git switch master &&
  41        git switch -c temp master^ &&
  42        test_cmp_rev master^ refs/heads/temp &&
  43        echo refs/heads/temp >expected-branch &&
  44        git symbolic-ref HEAD >actual-branch &&
  45        test_cmp expected-branch actual-branch
  46'
  47
  48test_expect_success 'force create branch from HEAD' '
  49        test_when_finished git switch master &&
  50        git switch --detach master &&
  51        test_must_fail git switch -c temp &&
  52        git switch -C temp &&
  53        test_cmp_rev master refs/heads/temp &&
  54        echo refs/heads/temp >expected-branch &&
  55        git symbolic-ref HEAD >actual-branch &&
  56        test_cmp expected-branch actual-branch
  57'
  58
  59test_expect_success 'new orphan branch from empty' '
  60        test_when_finished git switch master &&
  61        test_must_fail git switch --orphan new-orphan HEAD &&
  62        git switch --orphan new-orphan &&
  63        test_commit orphan &&
  64        git cat-file commit refs/heads/new-orphan >commit &&
  65        ! grep ^parent commit &&
  66        git ls-files >tracked-files &&
  67        echo orphan.t >expected &&
  68        test_cmp expected tracked-files
  69'
  70
  71test_expect_success 'switching ignores file of same branch name' '
  72        test_when_finished git switch master &&
  73        : >first-branch &&
  74        git switch first-branch &&
  75        echo refs/heads/first-branch >expected &&
  76        git symbolic-ref HEAD >actual &&
  77        test_cmp expected actual
  78'
  79
  80test_expect_success 'guess and create branch ' '
  81        test_when_finished git switch master &&
  82        test_must_fail git switch --no-guess foo &&
  83        git switch foo &&
  84        echo refs/heads/foo >expected &&
  85        git symbolic-ref HEAD >actual &&
  86        test_cmp expected actual
  87'
  88
  89test_expect_success 'not switching when something is in progress' '
  90        test_when_finished rm -f .git/MERGE_HEAD &&
  91        # fake a merge-in-progress
  92        cp .git/HEAD .git/MERGE_HEAD &&
  93        test_must_fail git switch -d @^
  94'
  95
  96test_done