t / t2070-restore.shon commit Merge branch 'tg/push-all-in-mirror-forbidden' (fe048e4)
   1#!/bin/sh
   2
   3test_description='restore basic functionality'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        test_commit first &&
   9        echo first-and-a-half >>first.t &&
  10        git add first.t &&
  11        test_commit second &&
  12        echo one >one &&
  13        echo two >two &&
  14        echo untracked >untracked &&
  15        echo ignored >ignored &&
  16        echo /ignored >.gitignore &&
  17        git add one two .gitignore &&
  18        git update-ref refs/heads/one master
  19'
  20
  21test_expect_success 'restore without pathspec is not ok' '
  22        test_must_fail git restore &&
  23        test_must_fail git restore --source=first
  24'
  25
  26test_expect_success 'restore a file, ignoring branch of same name' '
  27        cat one >expected &&
  28        echo dirty >>one &&
  29        git restore one &&
  30        test_cmp expected one
  31'
  32
  33test_expect_success 'restore a file on worktree from another ref' '
  34        test_when_finished git reset --hard &&
  35        git cat-file blob first:./first.t >expected &&
  36        git restore --source=first first.t &&
  37        test_cmp expected first.t &&
  38        git cat-file blob HEAD:./first.t >expected &&
  39        git show :first.t >actual &&
  40        test_cmp expected actual
  41'
  42
  43test_expect_success 'restore a file in the index from another ref' '
  44        test_when_finished git reset --hard &&
  45        git cat-file blob first:./first.t >expected &&
  46        git restore --source=first --staged first.t &&
  47        git show :first.t >actual &&
  48        test_cmp expected actual &&
  49        git cat-file blob HEAD:./first.t >expected &&
  50        test_cmp expected first.t
  51'
  52
  53test_expect_success 'restore a file in both the index and worktree from another ref' '
  54        test_when_finished git reset --hard &&
  55        git cat-file blob first:./first.t >expected &&
  56        git restore --source=first --staged --worktree first.t &&
  57        git show :first.t >actual &&
  58        test_cmp expected actual &&
  59        test_cmp expected first.t
  60'
  61
  62test_expect_success 'restore --staged uses HEAD as source' '
  63        test_when_finished git reset --hard &&
  64        git cat-file blob :./first.t >expected &&
  65        echo index-dirty >>first.t &&
  66        git add first.t &&
  67        git restore --staged first.t &&
  68        git cat-file blob :./first.t >actual &&
  69        test_cmp expected actual
  70'
  71
  72test_expect_success 'restore --ignore-unmerged ignores unmerged entries' '
  73        git init unmerged &&
  74        (
  75                cd unmerged &&
  76                echo one >unmerged &&
  77                echo one >common &&
  78                git add unmerged common &&
  79                git commit -m common &&
  80                git switch -c first &&
  81                echo first >unmerged &&
  82                git commit -am first &&
  83                git switch -c second master &&
  84                echo second >unmerged &&
  85                git commit -am second &&
  86                test_must_fail git merge first &&
  87
  88                echo dirty >>common &&
  89                test_must_fail git restore . &&
  90
  91                git restore --ignore-unmerged --quiet . >output 2>&1 &&
  92                git diff common >diff-output &&
  93                test_must_be_empty output &&
  94                test_must_be_empty diff-output
  95        )
  96'
  97
  98test_expect_success 'restore --staged adds deleted intent-to-add file back to index' '
  99        echo "nonempty" >nonempty &&
 100        >empty &&
 101        git add nonempty empty &&
 102        git commit -m "create files to be deleted" &&
 103        git rm --cached nonempty empty &&
 104        git add -N nonempty empty &&
 105        git restore --staged nonempty empty &&
 106        git diff --cached --exit-code
 107'
 108
 109test_done