githug icon indicating copy to clipboard operation
githug copied to clipboard

git_branch_current fails when h is not NULL but does not contain 'name'

Open restonslacker opened this issue 9 years ago • 3 comments
trafficstars

I have a git repo which doesn't contain a slot called "name" in the commit history. perhaps if (is.null(h)) could be changed to if (is.null(h) && !("name" %in% slotNames(h)))? Is there a better way to check for presence of a slot?

library(githug)
library(dplyr)
git_history(".") %>% mutate(author = "Foo Bar", email = "[email protected]") %>% 
    structure(class = c("git_history", class(.)))
#> # A tibble: 26 x 6
#>        sha                  message             when  author       email
#>      <chr>                    <chr>            <chr>   <chr>       <chr>
#> 1  4645b43 version inc and added t<U+0085> 2016-07-11 10:34 Foo Bar [email protected]
#> 2  79cc3e2 version inc              2016-07-11 10:31 Foo Bar [email protected]
#> 3  139f00b documentation update an<U+0085> 2016-01-20 14:40 Foo Bar [email protected]
#> 4  bf47182 closes #9, issue was ge<U+0085> 2015-10-26 16:05 Foo Bar [email protected]
#> 5  2732c1b closes #7, ggplot2 now <U+0085> 2015-09-08 10:58 Foo Bar [email protected]
#> 6  0f9a522 made color group more f<U+0085> 2015-09-07 11:27 Foo Bar [email protected]
#> 7  37fe067 release 0.1.2            2015-09-07 11:25 Foo Bar [email protected]
#> 8  8a81209 added examples for new <U+0085> 2015-09-01 11:58 Foo Bar [email protected]
#> 9  2457f6a closes #5, scales seem <U+0085> 2015-08-27 21:21 Foo Bar [email protected]
#> 10 a7336e6 closes #3 and closes #4<U+0085> 2015-08-27 21:20 Foo Bar [email protected]
#> # ... with 16 more rows, and 1 more variables: commit <list>
gr <- as.git_repository(".")
h <- git2r::head(gr)
slotNames(h)
#> [1] "sha"       "author"    "committer" "summary"   "message"   "repo"

restonslacker avatar Aug 24 '16 14:08 restonslacker

And you are not in a detached HEAD state? I suppose not. What does git branch report in the shell as the current branch? I didn't know it was possible for git2r to find HEAD but not report what branch it's pointing at.

jennybc avatar Aug 24 '16 15:08 jennybc

ahh... apparently I am in a detached HEAD state. This is the first time that I let JIRA make a branch in the repo so perhaps that has something to do with how i got here. Well, that's on me to figure out.

C:\Users\me\Documents\aviationgeoms>git branch
* (HEAD detached at origin/feature/CGRP-34-break-aviationgeoms)
  feature/real_geoms
  master

restonslacker avatar Aug 24 '16 17:08 restonslacker

I should still do something more intelligent here, so I'm glad to know about it. I have not been testing everything against detached HEAD state yet but it's on my list. I'm considering NOT helping people get into this state via githug but I must admit they will find other ways to get here!

jennybc avatar Aug 24 '16 18:08 jennybc