projects/guix·blob master · refs

94 lines · 3.0 KiB

1# GNU Guix --- Functional package management for GNU
2# Copyright © 2012, 2015-2016, 2024 Ludovic Courtès <[email protected]>
3#
4# This file is part of GNU Guix.
5#
6# GNU Guix is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or (at
9# your option) any later version.
10#
11# GNU Guix is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19# Define some files/folders needed for the tests.
20output="t-download-$$"
21test_git_repo="$(mktemp -d)"
22output_dir="t-archive-dir-$$"
23trap 'rm -rf "$test_git_repo" ; rm -f "$output" ; rm -rf "$output_dir"' EXIT
24
25#
26# Test the `guix download' command-line utility.
27#
28
29guix download --version
30
31# Make sure it fails here.
32guix download http://does.not/exist && false
33
34guix download unknown://some/where && false
35
36guix download /does-not-exist && false
37
38# This one should succeed.
39guix download "file://$abs_top_srcdir/README"
40
41# And this one, without the URI scheme.
42guix download "$abs_top_srcdir/README"
43
44# This one too, even if it cannot talk to the daemon.
45GUIX_DAEMON_SOCKET="/nowhere" guix download -o "$output" \
46 "file://$abs_top_srcdir/README"
47cmp "$output" "$abs_top_srcdir/README"
48
49# This one should fail.
50guix download "file:///does-not-exist" "file://$abs_top_srcdir/README" && false
51
52# Test git support with local repository.
53# First, create a dummy git repo in the temporary directory.
54(
55 # Avoid interference with user config.
56 GIT_CONFIG_GLOBAL=/dev/null
57 GIT_CONFIG_SYSTEM=/dev/null
58 export GIT_CONFIG_SYSTEM GIT_CONFIG_GLOBAL
59
60 cd $test_git_repo
61 git init
62 touch test
63 git config user.name "User"
64 git config user.email "user@domain"
65 git add test
66 git commit -m "Commit"
67 git tag -a -m "v1" v1
68)
69
70# Extract commit number.
71commit=$((cd $test_git_repo && git log) | head -n 1 | cut -f2 -d' ')
72
73# We expect that guix hash is working properly or at least that the output of
74# 'guix download' is consistent with 'guix hash'.
75expected_hash=$(guix hash -rx $test_git_repo)
76
77# Test the different options
78for option in "" "--commit=$commit" "--commit=v1" "--branch=master"
79do
80 command_output="$(guix download --git $option "file://$test_git_repo")"
81 computed_hash="$(echo $command_output | cut -f2 -d' ')"
82 store_path="$(echo $command_output | cut -f1 -d' ')"
83 [ "$expected_hash" = "$computed_hash" ]
84 diff -r -x ".git" $test_git_repo $store_path
85done
86
87# Should fail.
88guix download --git --branch=non_existent "file://$test_git_repo" && false
89
90# Same but download to file instead of store.
91guix download --git "file://$test_git_repo" -o $output_dir
92diff -r -x ".git" $test_git_repo $output_dir
93
94exit 0