File: push.t

package info (click to toggle)
git-subrepo 0.4.9-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,552 kB
  • sloc: sh: 7,074; makefile: 273; perl: 226
file content (177 lines) | stat: -rw-r--r-- 3,401 bytes parent folder | download | duplicates (2)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env bash

set -e

source test/setup

use Test::More

unset GIT_{AUTHOR,COMMITTER}_{EMAIL,NAME}

clone-foo-and-bar

# Make various changes to the repos for testing subrepo push:
(
  # In the main repo:
  cd "$OWNER/foo"

  # Clone the subrepo into a subdir
  git subrepo clone "$UPSTREAM/bar"

  # Make a series of commits:
  add-new-files bar/FooBar
  add-new-files ./FooBar
  modify-files bar/FooBar
  modify-files ./FooBar
  modify-files ./FooBar bar/FooBar
) &> /dev/null || die

(
  cd "$OWNER/bar"
  add-new-files bargy
  git push
) &> /dev/null || die

# Do the subrepo push and test the output:
{
  message=$(
    cd "$OWNER/foo"
    git config user.name 'PushUser'
    git config user.email 'push@push'
    git subrepo pull --quiet bar
    git subrepo push bar
  )

  # Test the output:
  is "$message" \
    "Subrepo 'bar' pushed to '$UPSTREAM/bar' (master)." \
    'push message is correct'
}

(
  cd "$OWNER/bar"
  git pull
) &> /dev/null || die

{
  pullCommit=$(
    cd "$OWNER/bar"
    git log HEAD -1 --pretty='format:%an %ae %cn %ce'
  )

  is "$pullCommit" \
    "PushUser push@push PushUser push@push" \
    "Pull commit has PushUser as both author and committer"
}

{
  subrepoCommit=$(
    cd "$OWNER/bar"
    git log HEAD^ -1 --pretty='format:%an %ae %cn %ce'
  )

  is "$subrepoCommit" \
    "FooUser foo@foo PushUser push@push" \
    "Subrepo commits has FooUser as author but PushUser as committer"
}

# Check that all commits arrived in subrepo
test-commit-count "$OWNER/bar" HEAD 7

# Test foo/bar/.gitrepo file contents:
# shellcheck disable=2034
gitrepo=$OWNER/foo/bar/.gitrepo
{
  foo_pull_commit=$(cd "$OWNER/foo"; git rev-parse HEAD^)
  bar_head_commit=$(cd "$OWNER/bar"; git rev-parse HEAD)
  test-gitrepo-field "remote" "$UPSTREAM/bar"
  test-gitrepo-field "branch" "master"
  test-gitrepo-field "commit" "$bar_head_commit"
  test-gitrepo-field "parent" "$foo_pull_commit"
  test-gitrepo-field "cmdver" "$(git subrepo --version)"
}

(
  # In the main repo:
  cd "$OWNER/foo"
  add-new-files bar/FooBar2
  modify-files bar/FooBar
) &> /dev/null || die

{
  message=$(
    cd "$OWNER/foo"
    git subrepo push bar
  )

  # Test the output:
  is "$message" \
    "Subrepo 'bar' pushed to '$UPSTREAM/bar' (master)." \
    'push message is correct'
}

# Pull the changes from UPSTREAM/bar in OWNER/bar
(
  cd "$OWNER/bar"
  git pull
) &> /dev/null || die

test-exists \
  "$OWNER/bar/Bar" \
  "$OWNER/bar/FooBar" \
  "$OWNER/bar/bard/" \
  "$OWNER/bar/bargy" \
  "!$OWNER/bar/.gitrepo" \

(
  # In the main repo:
  cd "$OWNER/foo"
  add-new-files bar/FooBar3
  modify-files bar/FooBar
  git subrepo push bar
  add-new-files bar/FooBar4
  modify-files bar/FooBar3
) &> /dev/null || die

{
  message=$(
    cd "$OWNER/foo"
    git subrepo push bar
  )

  # Test the output:
  is "$message" \
    "Subrepo 'bar' pushed to '$UPSTREAM/bar' (master)." \
    'Seqential pushes are correct'
}

(
  # In the subrepo
  cd "$OWNER/bar"
  git pull
  add-new-files barBar2
  git push
) &> /dev/null || die

(
  # In the main repo:
  cd "$OWNER/foo"
  add-new-files bar/FooBar5
  modify-files bar/FooBar3
) &> /dev/null || die

{
  message=$(
    cd "$OWNER/foo"
    git subrepo push bar 2>&1 || true
  )

  # Test the output:
  is "$message" \
    "git-subrepo: There are new changes upstream, you need to pull first." \
    'Stopped by other push'
}

done_testing

teardown