]>
Commit | Line | Data |
---|---|---|
683b5679 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git remote porcelain-ish' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
683b5679 JH |
7 | setup_repository () { |
8 | mkdir "$1" && ( | |
9 | cd "$1" && | |
10 | git init && | |
11 | >file && | |
12 | git add file && | |
13 | git commit -m "Initial" && | |
14 | git checkout -b side && | |
15 | >elif && | |
16 | git add elif && | |
17 | git commit -m "Second" && | |
18 | git checkout master | |
19 | ) | |
20 | } | |
21 | ||
22 | tokens_match () { | |
23 | echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect && | |
24 | echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual && | |
25 | diff -u expect actual | |
26 | } | |
27 | ||
28 | check_remote_track () { | |
29 | actual=$(git remote show "$1" | sed -n -e '$p') && | |
30 | shift && | |
31 | tokens_match "$*" "$actual" | |
32 | } | |
33 | ||
34 | check_tracking_branch () { | |
35 | f="" && | |
36 | r=$(git for-each-ref "--format=%(refname)" | | |
37 | sed -ne "s|^refs/remotes/$1/||p") && | |
38 | shift && | |
39 | tokens_match "$*" "$r" | |
40 | } | |
41 | ||
42 | test_expect_success setup ' | |
43 | ||
44 | setup_repository one && | |
45 | setup_repository two && | |
46 | ( | |
47 | cd two && git branch another | |
48 | ) && | |
49 | git clone one test | |
50 | ||
51 | ' | |
52 | ||
53 | test_expect_success 'remote information for the origin' ' | |
54 | ( | |
55 | cd test && | |
56 | tokens_match origin "$(git remote)" && | |
57 | check_remote_track origin master side && | |
58 | check_tracking_branch origin HEAD master side | |
59 | ) | |
60 | ' | |
61 | ||
62 | test_expect_success 'add another remote' ' | |
63 | ( | |
64 | cd test && | |
65 | git remote add -f second ../two && | |
66 | tokens_match "origin second" "$(git remote)" && | |
67 | check_remote_track origin master side && | |
68 | check_remote_track second master side another && | |
69 | check_tracking_branch second master side another && | |
70 | git for-each-ref "--format=%(refname)" refs/remotes | | |
71 | sed -e "/^refs\/remotes\/origin\//d" \ | |
72 | -e "/^refs\/remotes\/second\//d" >actual && | |
73 | >expect && | |
74 | diff -u expect actual | |
75 | ) | |
76 | ' | |
77 | ||
78 | test_expect_success 'remove remote' ' | |
79 | ( | |
80 | cd test && | |
81 | git remote rm second | |
82 | ) | |
83 | ' | |
84 | ||
85 | test_expect_success 'remove remote' ' | |
86 | ( | |
87 | cd test && | |
88 | tokens_match origin "$(git remote)" && | |
89 | check_remote_track origin master side && | |
90 | git for-each-ref "--format=%(refname)" refs/remotes | | |
91 | sed -e "/^refs\/remotes\/origin\//d" >actual && | |
92 | >expect && | |
93 | diff -u expect actual | |
94 | ) | |
95 | ' | |
96 | ||
4704640b JS |
97 | cat > test/expect << EOF |
98 | * remote origin | |
99 | URL: $(pwd)/one/.git | |
211c8968 | 100 | Remote branch merged with 'git pull' while on branch master |
4704640b | 101 | master |
211c8968 | 102 | New remote branch (next fetch will store in remotes/origin) |
4704640b JS |
103 | master |
104 | Tracked remote branches | |
105 | side master | |
106 | EOF | |
107 | ||
108 | test_expect_success 'show' ' | |
109 | (cd test && | |
110 | git config --add remote.origin.fetch \ | |
111 | refs/heads/master:refs/heads/upstream && | |
112 | git fetch && | |
113 | git branch -d -r origin/master && | |
114 | (cd ../one && | |
115 | echo 1 > file && | |
116 | git commit -m update file) && | |
117 | git remote show origin > output && | |
118 | git diff expect output) | |
119 | ' | |
120 | ||
121 | test_expect_success 'prune' ' | |
122 | (cd one && | |
123 | git branch -m side side2) && | |
124 | (cd test && | |
125 | git fetch origin && | |
126 | git remote prune origin && | |
127 | git rev-parse refs/remotes/origin/side2 && | |
128 | ! git rev-parse refs/remotes/origin/side) | |
129 | ' | |
130 | ||
683b5679 | 131 | test_done |