aboutsummaryrefslogtreecommitdiff
path: root/tests/rep-fetch-git-refname.testscript
blob: fe5b330f262c202fdfc2ced6d0b6d3fdb25c422b (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
# file      : tests/rep-fetch-git-refname.testscript
# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

: fetch
:
{
  $clone_root_cfg && $rep_add "$rep/state0/libfoo.git$fragment";

  if ($git_protocol == 'https-dumb')
    warn = "$warn_ref_hist$reason_dumb$warn_dumb"
  end;

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

: re-fetch
:
{
  : unchanged
  :
  {
    $clone_root_cfg && $rep_add "$rep/state0/libfoo.git$fragment";

    $* 2>!;

    $* 2>>~"%EOE%"
      %fetching git:.+libfoo$fragment%
      %querying .+libfoo\.git%
      1 package\(s\) in 1 repository\(s\)
      EOE
  }

  : changed
  :
  {
    g = git -C
    u = "$rep_git/state1"
    d = cfg/libfoo-1.0.0

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

    # Extract the repository path from the output line like this:
    #
    # fetching from <url> in 'cfg/.bpkg/tmp/4bde15f59461'...
    #
    $* --verbose 2 2>&1                               | \
      sed -n -e "s/fetching from .+ in '\(.+\)'/\$1/p"  | \
      sed -n -e 's%(.+[\\/])tmp([\\/].+)%$1repos$2%p' | \
      set r;

    # Note that the commit for doc/style/basic submodule is not at the branch
    # tip and so is not advertised.
    #
    warn1 = '%.{0}';
    warn2 = '%.{0}';
    warn3 = '%.{0}';

    if ($git_protocol == 'local'       || \
        $git_protocol == 'https-smart' || \
        $git_protocol == 'git')
      warn2 = "$warn_repo_hist for submodule 'doc/style/basic'$reason_unadv"
    elif ($git_protocol == 'https-dumb')
      warn1 = "$warn_ref_hist for submodule 'doc/style'$reason_dumb$warn_dumb"
      warn2 = "$warn_repo_hist for submodule 'doc/style/basic'$reason_dumb$warn_dumb"
      warn3 = "$warn_ref_hist for submodule 'libbar'$reason_dumb$warn_dumb"
    end;

    $pkg_checkout libfoo/1.0.0 2>>~"%EOE%";
      checking out libfoo/1.0.0
      %querying .+style\.git%?
      %fetching submodule 'doc/style' from .+style\.git%
      $warn1
      %submodule path 'doc/style': checked out .+%
      %querying .+style-basic\.git%?
      %fetching submodule 'doc/style/basic' from .+style-basic\.git%
      $warn2
      %submodule path 'doc/style/basic': checked out .+%
      %querying .+libbar\.git%?
      %fetching submodule 'libbar' from .+libbar\.git%
      $warn3
      %submodule path 'libbar': checked out .+%
      distributing libfoo/1.0.0
      checked out libfoo/1.0.0
      EOE

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

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

    if ($git_protocol == 'https-dumb')
      warn = "$warn_ref_hist$reason_dumb$warn_dumb"
    end;

    $* 2>>~"%EOE%" 1>&2;
      %fetching git:.+libfoo$fragment%
      %querying .+libfoo\.git%
      %fetching from .+libfoo\.git%
      $warn
      %warning: unable to rmdir .?libbar.?: .+%
      1 package\(s\) in 1 repository\(s\)
      EOE

    $pkg_drop libfoo;

    warn1 = '%.{0}';
    warn2 = '%.{0}';

    if ($git_protocol == 'https-dumb')
      warn1 = "$warn_ref_hist for submodule 'doc/style'$reason_dumb$warn_dumb"
      warn2 = "$warn_ref_hist for submodule 'libbaz'$reason_dumb$warn_dumb"
    end;

    $pkg_checkout libfoo/1.0.0 2>>~"%EOE%";
      checking out libfoo/1.0.0
      %querying .+style\.git%?
      %fetching submodule 'doc/style' from .+style\.git%
      $warn1
      %submodule path 'doc/style': checked out .+%
      %querying .+libbaz\.git%?
      %fetching submodule 'libbaz' from .+libbaz\.git%
      $warn2
      %submodule path 'libbaz': checked out .+%
      distributing libfoo/1.0.0
      checked out libfoo/1.0.0
      EOE

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

    $pkg_drop libfoo
  }
}