|
| 1 | +test_that("git_branch_create force applies to checkout", { |
| 2 | + repo <- git_init(tempfile("gert-tests-branch-force")) |
| 3 | + on.exit(unlink(repo, recursive = TRUE)) |
| 4 | + configure_local_user(repo) |
| 5 | + |
| 6 | + # First commit: hello.txt = "v1" |
| 7 | + writeLines("v1", file.path(repo, "hello.txt")) |
| 8 | + git_add("hello.txt", repo = repo) |
| 9 | + first <- git_commit("First commit", repo = repo) |
| 10 | + |
| 11 | + # Second commit: hello.txt = "v2" |
| 12 | + writeLines("v2", file.path(repo, "hello.txt")) |
| 13 | + git_add("hello.txt", repo = repo) |
| 14 | + git_commit("Second commit", repo = repo) |
| 15 | + |
| 16 | + # Unstaged local change: hello.txt = "v3" |
| 17 | + writeLines("v3", file.path(repo, "hello.txt")) |
| 18 | + |
| 19 | + # force = FALSE: checkout to first commit conflicts with local change |
| 20 | + expect_error( |
| 21 | + git_branch_create("oldbranch", ref = first, checkout = TRUE, force = FALSE, repo = repo) |
| 22 | + ) |
| 23 | + |
| 24 | + # force = TRUE: checkout succeeds, overwriting local change |
| 25 | + git_branch_create("oldbranch2", ref = first, checkout = TRUE, force = TRUE, repo = repo) |
| 26 | + expect_equal(git_branch(repo = repo), "oldbranch2") |
| 27 | + expect_equal(readLines(file.path(repo, "hello.txt")), "v1") |
| 28 | +}) |
0 commit comments