t / lib-git-p4.shon commit Merge branch 'jh/notes-merge-in-git-dir-worktree' (4e52008)
   1#
   2# Library code for git-p4 tests
   3#
   4
   5. ./test-lib.sh
   6
   7if ! test_have_prereq PYTHON; then
   8        skip_all='skipping git-p4 tests; python not available'
   9        test_done
  10fi
  11( p4 -h && p4d -h ) >/dev/null 2>&1 || {
  12        skip_all='skipping git-p4 tests; no p4 or p4d'
  13        test_done
  14}
  15
  16GITP4="$GIT_BUILD_DIR/contrib/fast-import/git-p4"
  17
  18# Try to pick a unique port: guess a large number, then hope
  19# no more than one of each test is running.
  20#
  21# This does not handle the case where somebody else is running the
  22# same tests and has chosen the same ports.
  23testid=${this_test#t}
  24git_p4_test_start=9800
  25P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
  26
  27export P4PORT=localhost:$P4DPORT
  28export P4CLIENT=client
  29
  30db="$TRASH_DIRECTORY/db"
  31cli="$TRASH_DIRECTORY/cli"
  32git="$TRASH_DIRECTORY/git"
  33pidfile="$TRASH_DIRECTORY/p4d.pid"
  34
  35start_p4d() {
  36        mkdir -p "$db" "$cli" "$git" &&
  37        (
  38                p4d -q -r "$db" -p $P4DPORT &
  39                echo $! >"$pidfile"
  40        ) &&
  41        for i in 1 2 3 4 5 ; do
  42                p4 info >/dev/null 2>&1 && break || true &&
  43                echo waiting for p4d to start &&
  44                sleep 1
  45        done &&
  46        # complain if it never started
  47        p4 info >/dev/null &&
  48        (
  49                cd "$cli" &&
  50                p4 client -i <<-EOF
  51                Client: client
  52                Description: client
  53                Root: $cli
  54                View: //depot/... //client/...
  55                EOF
  56        )
  57}
  58
  59kill_p4d() {
  60        pid=$(cat "$pidfile")
  61        # it had better exist for the first kill
  62        kill $pid &&
  63        for i in 1 2 3 4 5 ; do
  64                kill $pid >/dev/null 2>&1 || break
  65                sleep 1
  66        done &&
  67        # complain if it would not die
  68        test_must_fail kill $pid >/dev/null 2>&1 &&
  69        rm -rf "$db" "$cli" "$pidfile"
  70}
  71
  72cleanup_git() {
  73        rm -rf "$git"
  74}