Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jennybc/githug

Interface to local and remote Git operations
https://github.com/jennybc/githug

Last synced: about 1 month ago
JSON representation

Interface to local and remote Git operations

Awesome Lists containing this project

README

        

---
output: github_document
---

[![Project Status: Wip - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](http://www.repostatus.org/badges/0.1.0/wip.svg)](http://www.repostatus.org/#wip)

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-",
error = TRUE
)
```

# githug

### Welcome to Version Control!

![Demo](img/voldyhug-1440161473.gif)

The goal of githug is to wrap you in the warm embrace of Git 🤗, from the comfort of R.

*This a reboot of an earlier effort, which lives on in [branch `first-draft` ](https://github.com/jennybc/githug/tree/first-draft). That branch includes a function `githug_init()` to connect a new or existing R project (usually a RStudio Project) to a newly created GitHub remote. Currently plodding my way back to that level of functionality.*

## Installation

You can install githug from github with:

```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("jennybc/githug")
```

## Example

Load dev version of the package. *This will become `library(githug)`.*

```{r}
#library(githug)
devtools::load_all(".")
```

Create a new Git repository and set that as working directory for the duration of this example.

```{r}
repo <- git_init(tempfile("githug-example-"))
knitr::opts_knit$set(root.dir = repo)
```

Set (local) config variables for user and email.
Create two files and inspect Git status.

```{r}
git_config_local(user.name = "louise", user.email = "[email protected]")

write("Are these girls real smart or real real lucky?", "max.txt")
write("You get what you settle for.", "louise.txt")
git_status()
```

Commit with `all = TRUE` to automatically accept all current changes. *In interactive use, if `all` is unspecified, you get an offer to just stage all current changes.*

```{r}
git_commit(all = TRUE,
message = "Brains'll only get you so far and luck always runs out.")
```

Add new file and commit it. Inspect commit history.

```{r}
write("Did I hear somebody say \"Peaches\"?", "jimmy.txt")
git_commit("jimmy.txt", message = "That's the code word. I miss you, Peaches.")
git_history()
```

Uncommit, i.e. leave files as they are, but go back to parent of current commit.

```{r}
git_uncommit(ask = FALSE)
git_history()
```

Verify files and staging are OK. Unstage a file.

```{r}
git_status()
list.files()
git_unstage("jimmy.txt")
git_status()
```

See history.
Create and checkout a branch. *In an interactive session, if `create` is unspecified and branch does not exist, you are asked if you want to create the branch.* Go back to master.

```{r}
git_history()
git_branch()
git_switch("new_branch", create = TRUE)
git_branch()
git_switch()
git_branch_list()
```

## Overview of functions

```{r include = FALSE}
fxn_table <-
"fxn,description
git_config(), Get and set Git configuration variables
git_init(), Create a new repository
git_status(), Get status of all files w/r/t Git
git_history(), Get commit history (a.k.a. the log)
git_stage(), Stage (changes to) a path for next commit
git_add(), Synonym for git_stage()
git_unstage(), Unstage (changes to) a path
git_commit(), Make a commit
git_uncommit(), Undo a Git commit but leave files alone
git_amend(), Re-do the most recent commit
git_file_rename(), Rename or move and file and stage it
git_mv(), Synonym for git_file_rename()
git_branch(), Report current branch or list all branches
git_switch(), Switch to another branch
git_branch_*(), \"Lower level functions to list, create, rename, delete, and checkout branches\"
git_revision(), Identify a specific commit
as.git_repository(), Open a Git repo in the style of the `git2r` package
as.git_commit(), Get a specific commit in the style of the `git2r` package
"
```

```{r as.is = TRUE, echo = FALSE}
knitr::kable(read.csv(text = fxn_table))
```

*to be replaced by a proper test coverage badge*

```{r}
Sys.time()
git2r::repository("~/rrr/githug0")
covr::package_coverage("~/rrr/githug0/")
```