forked from r-lib/gert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-clone.R
More file actions
76 lines (71 loc) · 2.45 KB
/
Copy pathtest-clone.R
File metadata and controls
76 lines (71 loc) · 2.45 KB
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
test_that("cloning repositories works", {
skip_if_offline('github.com')
path <- file.path(tempdir(), 'gert')
repo <- git_clone('https://github.com/r-lib/gert', path = path)
expect_true(file.exists(file.path(path, 'DESCRIPTION')))
info <- git_info(repo)
default_head <- git_remote_ls(
'https://github.com/r-lib/gert',
repo = repo
)$symref[1]
default_branch <- basename(default_head)
expect_equal(info$head, default_head)
expect_equal(info$shorthand, default_branch)
repo2 <- git_open(path)
info2 <- git_info(repo2)
expect_equal(info, info2)
expect_is(git_ls(repo = repo), 'data.frame')
expect_is(git_log(repo = repo), 'data.frame')
heads <- git_remote_ls(repo = repo)
expect_is(heads, 'data.frame')
expect_equal(
git_remote_info(repo = repo)$head,
paste0("refs/remotes/origin/", default_branch)
)
# Test remotes
remotes <- git_remote_list(repo)
expect_equal(remotes$name, "origin")
expect_equal(remotes$url, "https://github.com/r-lib/gert")
# Test archive
expect_equal(git_archive_zip(repo = repo), 'gert.zip')
expect_equal(zip::zip_list('gert.zip')$filename, git_ls(repo = repo)$path)
unlink('gert.zip')
})
test_that("cloning repositories works, no path", {
skip_if_offline('github.com')
path <- file.path(tempdir(), 'gert-test')
dir.create(path)
on.exit(unlink(path, recursive = TRUE))
oldwd <- getwd()
on.exit(setwd(oldwd), add = TRUE)
setwd(path)
repo <- git_clone('https://github.com/r-lib/gert.git')
expect_true(file.exists(file.path(path, "gert", 'DESCRIPTION')))
})
test_that("shallow cloning with depth works", {
skip_if_offline('github.com')
skip_if_not(libgit2_config()$version >= "1.7.0")
path <- file.path(tempdir(), 'gert-shallow')
on.exit(unlink(path, recursive = TRUE))
repo <- git_clone('https://github.com/r-lib/gert', path = path, depth = 1)
expect_true(file.exists(file.path(path, 'DESCRIPTION')))
expect_equal(nrow(git_log(repo = repo)), 1L)
})
test_that("git_clone() validates depth argument", {
expect_error(
git_clone('https://github.com/r-lib/gert', depth = -1),
"`depth` must be an integer >= 0"
)
expect_error(
git_clone('https://github.com/r-lib/gert', depth = NA),
"`depth` must be an integer >= 0"
)
expect_error(
git_clone('https://github.com/r-lib/gert', depth = "a"),
"`depth` must be an integer >= 0"
)
expect_error(
git_clone('https://github.com/r-lib/gert', depth = c(1, 2)),
"`depth` must be an integer >= 0"
)
})