Created
February 1, 2021 20:34
-
-
Save djnavarro/fb1230ce1bb36d0de729829d819af256 to your computer and use it in GitHub Desktop.
use gert to scan multiple git repos for changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(gert) | |
git_overview <- function(path) { | |
# find root folders for all git repos | |
repo_list <- path %>% | |
list.dirs() %>% | |
str_subset("/.git$") %>% | |
str_remove_all("/.git$") | |
# retrieve the number of commits ahead/behind for all repos | |
repo_status <- repo_list %>% | |
map_dfr( | |
~ git_ahead_behind(repo = .x) %>% | |
as_tibble() %>% | |
mutate(repo = .x) %>% | |
select(repo, ahead, behind) | |
) | |
return(repo_status) | |
} | |
# a typical use case for me is to scan for repos in my local | |
# "~/GitHub folder" that have commits that I have forgotten to | |
# push to github (or, alternatively, forgotten to pull down | |
# from github) | |
git_overview("~/GitHub") %>% | |
filter(ahead > 0 | behind > 0) %>% | |
print() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment