forked from r-lib/gert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-remotes.R
More file actions
127 lines (118 loc) · 4.04 KB
/
Copy pathtest-remotes.R
File metadata and controls
127 lines (118 loc) · 4.04 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
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
test_that("git_remote_set_pushurl with add = TRUE appends push URLs", {
repo <- git_init(tempfile("gert-tests-pushurl"))
on.exit(unlink(repo, recursive = TRUE))
configure_local_user(repo)
git_remote_add("https://example.com/fetch", name = "origin", repo = repo)
git_remote_set_pushurl(
"https://example.com/push1",
remote = "origin",
repo = repo
)
git_remote_set_pushurl(
"https://example.com/push2",
remote = "origin",
add = TRUE,
repo = repo
)
pushurls <- git_config_get("remote.origin.pushurl", repo = repo)
expect_setequal(
pushurls,
c("https://example.com/push1", "https://example.com/push2")
)
})
test_that("git_remote_set_pushurl without add replaces push URL", {
repo <- git_init(tempfile("gert-tests-pushurl-replace"))
on.exit(unlink(repo, recursive = TRUE))
configure_local_user(repo)
git_remote_add("https://example.com/fetch", name = "origin", repo = repo)
git_remote_set_pushurl(
"https://example.com/push1",
remote = "origin",
repo = repo
)
git_remote_set_pushurl(
"https://example.com/push2",
remote = "origin",
repo = repo
)
pushurls <- git_config_get("remote.origin.pushurl", repo = repo)
expect_equal(pushurls, "https://example.com/push2")
})
test_that("remotes from new repo", {
skip_if_offline('github.com')
repo <- git_init(tempfile("gert-tests-remote"))
on.exit(unlink(repo, recursive = TRUE))
expect_equal(nrow(git_remote_list(repo = repo)), 0)
expect_error(git_remote_info(repo = repo))
expect_error(git_remote_refspecs(repo = repo))
expect_error(git_remote_set_url('https://github.com/foo/bar', repo = repo))
expect_error(git_remote_info(repo = repo), "remote 'NA' does not exist")
expect_error(git_remote_set_pushurl(
'https://github.com/foo/bar',
repo = repo
))
expect_error(git_remote_info(repo = repo), "remote 'NA' does not exist")
expect_equal(
git_remote_add(
'https://github.com/jeroen/webp',
name = 'jeroen',
repo = repo
),
'jeroen'
)
# info should work even when no upstream:
info <- git_remote_info(repo = repo)
expect_equal(info$url, "https://github.com/jeroen/webp")
git_fetch('jeroen', 'master', repo = repo)
git_branch_create('master', 'jeroen/master', repo = repo)
git_branch_create(
'testje',
git_commit_id('jeroen/master', repo = repo),
checkout = FALSE,
repo = repo
)
git_remote_set_pushurl('https://github.com/foo/baz', repo = repo)
info <- git_remote_info(repo = repo)
expect_equal(info$name, 'jeroen')
expect_equal(info$url, "https://github.com/jeroen/webp")
expect_equal(info$push_url, "https://github.com/foo/baz")
expect_equal(info$fetch, "+refs/heads/*:refs/remotes/jeroen/*")
branches <- git_branch_list(repo = repo)
expect_equal(branches$name, c("master", "testje", "jeroen/master"))
expect_equal(branches$upstream, c("refs/remotes/jeroen/master", NA, NA))
})
test_that("remotes after clone", {
skip_if_offline('github.com')
repo <- file.path(tempdir(), 'gert')
if (!file.exists(repo)) {
git_clone('https://github.com/r-lib/gert', path = repo)
}
info <- git_remote_info(repo = repo)
expect_equal(info$name, 'origin')
expect_equal(info$url, "https://github.com/r-lib/gert")
expect_equal(info$fetch, "+refs/heads/*:refs/remotes/origin/*")
refspecs <- git_remote_refspecs(repo = repo)
expect_equal(refspecs$direction, 'fetch')
remotelist <- git_remote_list(repo = repo)
expect_equal(remotelist$name, 'origin')
expect_equal(remotelist$url, 'https://github.com/r-lib/gert')
expect_error(git_remote_add('https://github.com/jeroen/gert', repo = repo))
expect_equal(
git_remote_add(
'https://github.com/jeroen/gert',
name = 'myfork',
repo = repo
),
'myfork'
)
remotelist <- git_remote_list(repo = repo)
expect_equal(sort(remotelist$name), c("myfork", 'origin'))
expect_equal(
sort(remotelist$url),
c("https://github.com/jeroen/gert", 'https://github.com/r-lib/gert')
)
expect_equal(
git_remote_refspecs('myfork', repo = repo)$refspec,
'+refs/heads/*:refs/remotes/myfork/*'
)
})