Check if HEAD of repository is detached

Share:

Description

Check if HEAD of repository is detached

Usage

1
2
3
4
5
6
7
is_detached(repo)

## S4 method for signature 'missing'
is_detached()

## S4 method for signature 'git_repository'
is_detached(repo)

Arguments

repo

The repository object git_repository. If the repo argument is missing, the repository is searched for with discover_repository in the current working directory.

Value

TRUE if repository HEAD is detached, else FALSE

Examples

 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
## Not run: 
## Create and initialize a repository in a temporary directory
path <- tempfile(pattern="git2r-")
dir.create(path)
repo <- init(path)
config(repo, user.name="Alice", user.email="alice@example.org")

## Create a file, add and commit
writeLines("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do",
           file.path(path, "example.txt"))
add(repo, "example.txt")
commit_1 <- commit(repo, "Commit message 1")

## Change file, add and commit
writeLines(c("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do",
             "eiusmod tempor incididunt ut labore et dolore magna aliqua."),
             file.path(path, "example.txt"))
add(repo, "example.txt")
commit(repo, "Commit message 2")

## HEAD of repository is not detached
is_detached(repo)

## Checkout first commit
checkout(commit_1)

## HEAD of repository is detached
is_detached(repo)

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.