t / t1306-xdg-files.shon commit git p4: remove unused imports (f629fa5)
   1#!/bin/sh
   2#
   3# Copyright (c) 2012 Valentin Duperray, Lucien Kong, Franck Jonas,
   4#                    Thomas Nguy, Khoi Nguyen
   5#                    Grenoble INP Ensimag
   6#
   7
   8test_description='Compatibility with $XDG_CONFIG_HOME/git/ files'
   9
  10. ./test-lib.sh
  11
  12test_expect_success 'read config: xdg file exists and ~/.gitconfig doesn'\''t' '
  13        mkdir -p .config/git &&
  14        echo "[alias]" >.config/git/config &&
  15        echo "  myalias = !echo in_config" >>.config/git/config &&
  16        echo in_config >expected &&
  17        git myalias >actual &&
  18        test_cmp expected actual
  19'
  20
  21
  22test_expect_success 'read config: xdg file exists and ~/.gitconfig exists' '
  23        >.gitconfig &&
  24        echo "[alias]" >.gitconfig &&
  25        echo "  myalias = !echo in_gitconfig" >>.gitconfig &&
  26        echo in_gitconfig >expected &&
  27        git myalias >actual &&
  28        test_cmp expected actual
  29'
  30
  31
  32test_expect_success 'read with --get: xdg file exists and ~/.gitconfig doesn'\''t' '
  33        rm .gitconfig &&
  34        echo "[user]" >.config/git/config &&
  35        echo "  name = read_config" >>.config/git/config &&
  36        echo read_config >expected &&
  37        git config --get user.name >actual &&
  38        test_cmp expected actual
  39'
  40
  41test_expect_success '"$XDG_CONFIG_HOME overrides $HOME/.config/git' '
  42        mkdir -p "$HOME"/xdg/git &&
  43        echo "[user]name = in_xdg" >"$HOME"/xdg/git/config &&
  44        echo in_xdg >expected &&
  45        XDG_CONFIG_HOME="$HOME"/xdg git config --get-all user.name >actual &&
  46        test_cmp expected actual
  47'
  48
  49test_expect_success 'read with --get: xdg file exists and ~/.gitconfig exists' '
  50        >.gitconfig &&
  51        echo "[user]" >.gitconfig &&
  52        echo "  name = read_gitconfig" >>.gitconfig &&
  53        echo read_gitconfig >expected &&
  54        git config --get user.name >actual &&
  55        test_cmp expected actual
  56'
  57
  58
  59test_expect_success 'read with --list: xdg file exists and ~/.gitconfig doesn'\''t' '
  60        rm .gitconfig &&
  61        echo user.name=read_config >expected &&
  62        git config --global --list >actual &&
  63        test_cmp expected actual
  64'
  65
  66
  67test_expect_success 'read with --list: xdg file exists and ~/.gitconfig exists' '
  68        >.gitconfig &&
  69        echo "[user]" >.gitconfig &&
  70        echo "  name = read_gitconfig" >>.gitconfig &&
  71        echo user.name=read_gitconfig >expected &&
  72        git config --global --list >actual &&
  73        test_cmp expected actual
  74'
  75
  76
  77test_expect_success 'Setup' '
  78        git init git &&
  79        cd git &&
  80        echo foo >to_be_excluded
  81'
  82
  83
  84test_expect_success 'Exclusion of a file in the XDG ignore file' '
  85        mkdir -p "$HOME"/.config/git/ &&
  86        echo to_be_excluded >"$HOME"/.config/git/ignore &&
  87        test_must_fail git add to_be_excluded
  88'
  89
  90test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/ignore' '
  91        mkdir -p "$HOME"/xdg/git &&
  92        echo content >excluded_by_xdg_only &&
  93        echo excluded_by_xdg_only >"$HOME"/xdg/git/ignore &&
  94        test_when_finished "git read-tree --empty" &&
  95        (XDG_CONFIG_HOME="$HOME/xdg" &&
  96         export XDG_CONFIG_HOME &&
  97         git add to_be_excluded &&
  98         test_must_fail git add excluded_by_xdg_only
  99        )
 100'
 101
 102test_expect_success 'Exclusion in both XDG and local ignore files' '
 103        echo to_be_excluded >.gitignore &&
 104        test_must_fail git add to_be_excluded
 105'
 106
 107
 108test_expect_success 'Exclusion in a non-XDG global ignore file' '
 109        rm .gitignore &&
 110        echo >"$HOME"/.config/git/ignore &&
 111        echo to_be_excluded >"$HOME"/my_gitignore &&
 112        git config core.excludesfile "$HOME"/my_gitignore &&
 113        test_must_fail git add to_be_excluded
 114'
 115
 116test_expect_success 'Checking XDG ignore file when HOME is unset' '
 117        >expected &&
 118        (sane_unset HOME &&
 119         git config --unset core.excludesfile &&
 120         git ls-files --exclude-standard --ignored >actual) &&
 121        test_cmp expected actual
 122'
 123
 124test_expect_success 'Checking attributes in the XDG attributes file' '
 125        echo foo >f &&
 126        git check-attr -a f >actual &&
 127        test_line_count -eq 0 actual &&
 128        echo "f attr_f" >"$HOME"/.config/git/attributes &&
 129        echo "f: attr_f: set" >expected &&
 130        git check-attr -a f >actual &&
 131        test_cmp expected actual
 132'
 133
 134test_expect_success 'Checking XDG attributes when HOME is unset' '
 135        >expected &&
 136        (sane_unset HOME &&
 137         git check-attr -a f >actual) &&
 138        test_cmp expected actual
 139'
 140
 141test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/attributes' '
 142        mkdir -p "$HOME"/xdg/git &&
 143        echo "f attr_f=xdg" >"$HOME"/xdg/git/attributes &&
 144        echo "f: attr_f: xdg" >expected &&
 145        XDG_CONFIG_HOME="$HOME/xdg" git check-attr -a f >actual &&
 146        test_cmp expected actual
 147'
 148
 149test_expect_success 'Checking attributes in both XDG and local attributes files' '
 150        echo "f -attr_f" >.gitattributes &&
 151        echo "f: attr_f: unset" >expected &&
 152        git check-attr -a f >actual &&
 153        test_cmp expected actual
 154'
 155
 156
 157test_expect_success 'Checking attributes in a non-XDG global attributes file' '
 158        test_might_fail rm .gitattributes &&
 159        echo "f attr_f=test" >"$HOME"/my_gitattributes &&
 160        git config core.attributesfile "$HOME"/my_gitattributes &&
 161        echo "f: attr_f: test" >expected &&
 162        git check-attr -a f >actual &&
 163        test_cmp expected actual
 164'
 165
 166
 167test_expect_success 'write: xdg file exists and ~/.gitconfig doesn'\''t' '
 168        mkdir -p "$HOME"/.config/git &&
 169        >"$HOME"/.config/git/config &&
 170        test_might_fail rm "$HOME"/.gitconfig &&
 171        git config --global user.name "write_config" &&
 172        echo "[user]" >expected &&
 173        echo "  name = write_config" >>expected &&
 174        test_cmp expected "$HOME"/.config/git/config
 175'
 176
 177
 178test_expect_success 'write: xdg file exists and ~/.gitconfig exists' '
 179        >"$HOME"/.gitconfig &&
 180        git config --global user.name "write_gitconfig" &&
 181        echo "[user]" >expected &&
 182        echo "  name = write_gitconfig" >>expected &&
 183        test_cmp expected "$HOME"/.gitconfig
 184'
 185
 186
 187test_expect_success 'write: ~/.config/git/ exists and config file doesn'\''t' '
 188        test_might_fail rm "$HOME"/.gitconfig &&
 189        test_might_fail rm "$HOME"/.config/git/config &&
 190        git config --global user.name "write_gitconfig" &&
 191        echo "[user]" >expected &&
 192        echo "  name = write_gitconfig" >>expected &&
 193        test_cmp expected "$HOME"/.gitconfig
 194'
 195
 196
 197test_done