File: test_git.sh

package info (click to toggle)
liquidprompt 2.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,572 kB
  • sloc: sh: 3,621; python: 33; makefile: 15
file content (77 lines) | stat: -rw-r--r-- 1,677 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

# Error on unset variables
set -u

if [ -n "${ZSH_VERSION-}" ]; then
  SHUNIT_PARENT="$0"
  setopt shwordsplit
fi

. ../liquidprompt --no-activate

function test_git {

    LP_ENABLE_GIT=1
    LP_ENABLE_FOSSIL=0
    LP_ENABLE_SVN=0
    LP_ENABLE_BZR=0
    LP_ENABLE_VCS_ROOT=0
    LP_ENABLE_VCS_REMOTE=1

    PS1=""
    lp_activate

    wd="${SHUNIT_TMPDIR}/test_remote/"
    mkdir -p "$wd"
    cd "$wd"

    _lp_are_vcs_enabled
    assertTrue "VCS are enabled here." "$?"

    git init
    git config --local user.email "author@example.com"
    git config --local user.name "A U Thor"
    # We need a commit to have a branch that can have a remote.
    touch test
    git add test
    git commit -m "test" --no-verify --no-gpg-sign
    # Ensure we use "main" and not "master".
    git branch -m main

    _lp_find_vcs
    assertTrue "We detect a VCS updir." "$?"
    assertEquals "We found a Git repo." "git" "$lp_vcs_type"
    assertEquals "We see the repo." "$wd" "$lp_vcs_root/"

    _lp_vcs_active
    assertTrue "Git detects the repository." "$?"

    git checkout -b notsomain

    _lp_vcs_branch
    assertEquals "Branch change is detected." "notsomain" "$lp_vcs_branch"

    # Use a local remote or else one could have problems.
    git branch -u main

    _lp_git_remote
    assertEquals "Remote is found." "." "$lp_vcs_remote"


    mkdir remote/
    cp -r .git remote/

    git remote add foo ./remote/
    git fetch foo
    git checkout -b other

    _lp_vcs_branch
    assertEquals "Branch change is detected." "other" "$lp_vcs_branch"

    git branch -u foo/main

    _lp_git_remote
    assertEquals "Remote foo is found." "foo" "$lp_vcs_remote"
}

. ./shunit2