aboutsummaryrefslogtreecommitdiff
path: root/tests/rep-fetch-git-branch.test
blob: 86f5cb1b7306b1fc5218af6019b5004da4920c16 (plain)
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
# file      : tests/rep-fetch-git-branch.test
# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

reason_dumb  = ' (dumb HTTP)'
reason_unadv = ' (unadvertised commit)'

warn_dumb='
warning: fetching over dumb HTTP, no progress will be shown'

: clone
:
{
  $clone_root_cfg && $rep_add "$rep/state0/libfoo.git#$branch";

  # Note that the commit for doc/style/basic submodule is not at the branch tip
  # and so is not advertised.
  #
  if ($git_protocol == 'local' || \
      $git_protocol == 'https-smart' || \
      $git_protocol == 'git')
    warn1 = '%.{0}'
    warn2 = '%.{0}'
    warn3 = "warning: fetching whole repository history for submodule 'doc/style/basic'$reason_unadv"
    fetch = '%.{0}'
    warn4 = '%.{0}'
  elif ($git_protocol == 'https-dumb')
    warn1 = "warning: fetching whole branch history$reason_dumb$warn_dumb"
    warn2 = "warning: fetching whole repository history for submodule 'doc/style'$reason_dumb$warn_dumb"
    warn3 = "warning: fetching whole repository history for submodule 'doc/style/basic'$reason_dumb$warn_dumb"
    fetch = '%.{0}'
    warn4 = "warning: fetching whole repository history for submodule 'libbar'$reason_dumb$warn_dumb"
  elif ($git_protocol == 'https-smart-unadv')
    warn1 = '%.{0}'
    warn2 = '%.{0}'
    warn3 = '%.{0}'
    fetch = "%Fetching in '.+style/basic'.+%"
    warn4 = '%.{0}'
  end;

  $* 2>>~"%EOE%"
    %fetching git:.+libfoo%
    $warn1
    %Cloning into '.+$branch'.+%
    %Submodule 'doc/style' .+ registered for path 'doc/style'%
    %Submodule 'libbar' .+ registered for path 'libbar'%
    $warn2
    %Cloning into '.+doc/style'.+%
    %Submodule path 'doc/style': checked out .+%
    %Submodule 'basic' .+ registered for path 'doc/style/basic'%
    $warn3
    %Cloning into '.+doc/style/basic'.+%
    $fetch
    %Submodule path 'doc/style/basic': checked out .+%
    $warn4
    %Cloning into '.+libbar'.+%
    %Submodule path 'libbar': checked out .+%
    1 package\(s\) in 1 repository\(s\)
    EOE
}

: fetch
:
{
  : unchanged
  :
  {
    $clone_root_cfg && $rep_add "$rep/state0/libfoo.git#$branch";

    # Convert specific warnings to infos as we expect them to appear. This, in
    # particular, prevents bbot workers to set task result status to warning.
    #
    $* 2>&1 | sed -e 's/warning: (fetching (over|whole) .*)/info: \1/' >&2 2>!;

    if ($git_protocol == 'https-dumb')
      warn = "warning: fetching whole branch history$reason_dumb$warn_dumb"
    else
      warn = '%.{0}'
    end;

    $* 2>>~"%EOE%"
      %fetching git:.+libfoo%
      $warn
      %Fetching in '.+$branch'.+%
      1 package\(s\) in 1 repository\(s\)
      EOE
  }

  : changed
  :
  {
    g = git -C
    u = "$rep_git/state1"

    $clone_root_cfg && $rep_add "$rep/state0/libfoo.git#$branch";

    # Extract the repository path from the output line like this:
    #
    # Cloning into 'cfg\.bpkg\tmp\f9be881264703b5d\master'...
    #
    $* 2>&1 | sed -n -e "s/Cloning into '\(.+$branch\)'\.{3}/\$1/p"  | \
              sed -n -e 's%(.+[\\/])tmp([\\/].+)%$1repositories$2%p' | \
              set r;

    $g "$r" config remote.origin.url       "$u/libfoo.git";

    $g "$r" config submodule.libbar.url    "$u/libbar.git";
    $g "$r" config submodule.doc/style.url "$u/style.git";

    $g "$r/libbar" config remote.origin.url "$u/libbar.git";

    $g "$r/doc/style" config remote.origin.url   "$u/style.git";
    $g "$r/doc/style" config submodule.basic.url "$u/style-basic.git";

    $g "$r/doc/style/basic" config remote.origin.url "$u/style-basic.git";

    # Preconditions.
    #
    test -f $r/tests/TODO;
    test -f $r/libbar/libbar/manifest;
    test -f $r/doc/style/README != 0;
    test -d $r/libbaz != 0;

    if ($git_protocol == 'https-dumb')
      warn1 = "warning: fetching whole branch history$reason_dumb$warn_dumb"
      warn2 = "warning: fetching whole repository history for submodule 'doc/style'$reason_dumb$warn_dumb"
      warn3 = "warning: fetching whole repository history for submodule 'libbaz'$reason_dumb$warn_dumb"
    else
      warn1 = '%.{0}'
      warn2 = '%.{0}'
      warn3 = '%.{0}'
    end;

    $* 2>>~"%EOE%" 1>&2;
      %fetching git:.+libfoo%
      $warn1
      %Fetching in '.+$branch'.+%
      %warning: unable to rmdir '?libbar'?:.+%
      %Submodule 'libbaz' .+ registered for path 'libbaz'%
      $warn2
      %Fetching in '.+doc/style'.+%
      %Submodule path 'doc/style': checked out .+%
      $warn3
      %Cloning into '.+libbaz'.+%
      %Submodule path 'libbaz': checked out .+%
      1 package\(s\) in 1 repository\(s\)
      EOE

    # Postconditions.
    #
    test -d $r/tests != 0;
    test -d $r/libbar != 0;
    test -f $r/doc/style/README;
    test -f $r/libbaz/manifest
  }
}