Skip to content

Commit e895909

Browse files
mpadgemaelle
andauthored
if no remote upstream, return remote address if single; fixes #131 (#263)
* if no remote upstream, return remote address if single; fixes #131 * add tests for #131 * add expected error patterns in tests for #131 * docs: add changelog item --------- Co-authored-by: Maëlle Salmon <maelle.salmon@yahoo.se>
1 parent dbe9484 commit e895909

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# gert (development version)
22

3+
- Fix `git_info()` for the case when no upstream is configured (@mpage, #263)
34
- `git_branch_create()`: `force` now also applies to the checkout step, allowing branch creation even when local changes would be overwritten (@MichaelChirico, #177).
45
- Improve manual pages (@olivroy, #227)
56
- Fix badge links in `README.md` (@dpprdan, #189)

src/files.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ SEXP R_git_repository_info(SEXP ptr){
4141
git_reference_free(head);
4242
}
4343

44+
/* If remote still NA (no upstream configured), use sole remote if exactly one */
45+
if(STRING_ELT(remote, 0) == NA_STRING){
46+
git_strarray remotes = {0};
47+
if(git_remote_list(&remotes, repo) == 0 && remotes.count == 1)
48+
SET_STRING_ELT(remote, 0, safe_char(remotes.strings[0]));
49+
git_strarray_free(&remotes);
50+
}
51+
4452
SEXP out = build_list(8, "path", path, "bare", bare, "head", headref, "shorthand", shorthand,
4553
"commit", target, "remote", remote, "upstream", upstream, "reflist", refs);
4654
UNPROTECT(8);

tests/testthat/test-remotes.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ test_that("remotes from new repo", {
66
expect_error(git_remote_info(repo = repo))
77
expect_error(git_remote_refspecs(repo = repo))
88
expect_error(git_remote_set_url('https://github.com/foo/bar', repo = repo))
9+
expect_error(git_remote_info(repo = repo), "remote 'NA' does not exist")
910
expect_error(git_remote_set_pushurl(
1011
'https://github.com/foo/bar',
1112
repo = repo
1213
))
14+
expect_error(git_remote_info(repo = repo), "remote 'NA' does not exist")
1315
expect_equal(
1416
git_remote_add(
1517
'https://github.com/jeroen/webp',
@@ -18,6 +20,9 @@ test_that("remotes from new repo", {
1820
),
1921
'jeroen'
2022
)
23+
# info should work even when no upstream:
24+
info <- git_remote_info(repo = repo)
25+
expect_equal(info$url, "https://github.com/jeroen/webp")
2126
git_fetch('jeroen', 'master', repo = repo)
2227
git_branch_create('master', 'jeroen/master', repo = repo)
2328
git_branch_create(

0 commit comments

Comments
 (0)