github.com/naive/revgrep@v0.0.0-20240331191128-ab485935cedc/testdata/make.sh (about)

     1  #!/usr/bin/env bash
     2  set -u
     3  
     4  if [[ "$(basename $(pwd))" != "testdata" ]]; then
     5      echo Run for testdata dir
     6      exit 1
     7  fi
     8  
     9  [[ -d git ]] && rm -rf git
    10  mkdir -p git/subdir && cd git
    11  
    12  # No git directory
    13  
    14  [[ "$1" == "1-non-git-dir" ]] && exit
    15  
    16  # Untracked files
    17  
    18  git init --initial-branch=main
    19  git config --local user.name "testdata"
    20  git config --local user.email "testdata@example.com"
    21  git config --local color.diff always
    22  
    23  if [[ "$(go env GOOS)" == "windows" ]]; then
    24      git config --local core.autocrlf false
    25  fi
    26  
    27  touch readme
    28  git add .
    29  git commit -m "Initial commit"
    30  
    31  cat > main.go <<'EOF'
    32  package main
    33  import "fmt"
    34  var _ = fmt.Sprintf("2-untracked %s")
    35  func main() {}
    36  EOF
    37  
    38  [[ "$1" == "2-untracked" ]] && exit
    39  
    40  # Untracked files with sub dir
    41  
    42  cat > subdir/main.go <<'EOF'
    43  package main
    44  import "fmt"
    45  var _ = fmt.Sprintf("3-untracked-subdir %s")
    46  func main() {}
    47  EOF
    48  
    49  [[ "$1" == "3-untracked-subdir" ]] && exit
    50  
    51  # Placeholder for test to change to sub directory
    52  
    53  [[ "$1" == "3-untracked-subdir-cwd" ]] && exit
    54  
    55  # Commit
    56  
    57  git add .
    58  git commit -m "Commit"
    59  
    60  [[ "$1" == "4-commit" ]] && exit
    61  
    62  # Unstage changes without warning
    63  
    64  cat >> main.go <<'EOF'
    65  var _ = fmt.Sprintln("5-unstaged-no-warning")
    66  EOF
    67  
    68  [[ "$1" == "5-unstaged-no-warning" ]] && exit
    69  
    70  cat >> main.go <<'EOF'
    71  var _ = fmt.Sprintf("6-unstaged %s")
    72  EOF
    73  
    74  [[ "$1" == "6-unstaged" ]] && exit
    75  
    76  # Commit all changes
    77  
    78  git add .
    79  git commit -m "Commit"
    80  
    81  [[ "$1" == "7-commit" ]] && exit
    82  
    83  cat >> main.go <<'EOF'
    84  var _ = fmt.Sprintf("8-unstaged %s")
    85  EOF
    86  
    87  [[ "$1" == "8-unstaged" ]] && exit
    88  
    89  cat > main2.go <<'EOF'
    90  package main
    91  import "fmt"
    92  var _ = fmt.Sprintf("9-untracked %s")
    93  EOF
    94  
    95  [[ "$1" == "9-untracked" ]] && exit
    96  
    97  # Placeholder for test to check committed changes
    98  
    99  [[ "$1" == "10-committed" ]] && exit
   100  
   101  # Display absolute path
   102  
   103  [[ "$1" == "11-abs-path" ]] && exit
   104  
   105  # Remove one line on a file with existing issues
   106  
   107  if [[ "$1" == "12-removed-lines" ]]; then
   108  
   109      cat > 12-removed-lines.go <<'EOF'
   110  package main
   111  import "fmt"
   112  var _ = fmt.Sprintf("12-removed-lines %s")
   113  // some comment that will be removed
   114  EOF
   115  
   116      git add .
   117      git commit -m "Commit"
   118  
   119      cat > 12-removed-lines.go <<'EOF'
   120  package main
   121  import "fmt"
   122  var _ = fmt.Sprintf("12-removed-lines %s")
   123  EOF
   124  
   125      git add .
   126      git commit -m "Commit"
   127  fi