1#!/bin/sh
2
3test_description='git remote porcelain-ish'
4
5. ./test-lib.sh
6
7GIT_CONFIG=.git/config
8export GIT_CONFIG
9
10setup_repository () {
11 mkdir "$1" && (
12 cd "$1" &&
13 git init &&
14 >file &&
15 git add file &&
16 git commit -m "Initial" &&
17 git checkout -b side &&
18 >elif &&
19 git add elif &&
20 git commit -m "Second" &&
21 git checkout master
22 )
23}
24
25tokens_match () {
26 echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect &&
27 echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual &&
28 diff -u expect actual
29}
30
31check_remote_track () {
32 actual=$(git remote show "$1" | sed -n -e '$p') &&
33 shift &&
34 tokens_match "$*" "$actual"
35}
36
37check_tracking_branch () {
38 f="" &&
39 r=$(git for-each-ref "--format=%(refname)" |
40 sed -ne "s|^refs/remotes/$1/||p") &&
41 shift &&
42 tokens_match "$*" "$r"
43}
44
45test_expect_success setup '
46
47 setup_repository one &&
48 setup_repository two &&
49 (
50 cd two && git branch another
51 ) &&
52 git clone one test
53
54'
55
56test_expect_success 'remote information for the origin' '
57(
58 cd test &&
59 tokens_match origin "$(git remote)" &&
60 check_remote_track origin master side &&
61 check_tracking_branch origin HEAD master side
62)
63'
64
65test_expect_success 'add another remote' '
66(
67 cd test &&
68 git remote add -f second ../two &&
69 tokens_match "origin second" "$(git remote)" &&
70 check_remote_track origin master side &&
71 check_remote_track second master side another &&
72 check_tracking_branch second master side another &&
73 git for-each-ref "--format=%(refname)" refs/remotes |
74 sed -e "/^refs\/remotes\/origin\//d" \
75 -e "/^refs\/remotes\/second\//d" >actual &&
76 >expect &&
77 diff -u expect actual
78)
79'
80
81test_expect_success 'remove remote' '
82(
83 cd test &&
84 git remote rm second
85)
86'
87
88test_expect_success 'remove remote' '
89(
90 cd test &&
91 tokens_match origin "$(git remote)" &&
92 check_remote_track origin master side &&
93 git for-each-ref "--format=%(refname)" refs/remotes |
94 sed -e "/^refs\/remotes\/origin\//d" >actual &&
95 >expect &&
96 diff -u expect actual
97)
98'
99
100test_done