MyNixOS website logo
Description

A Lightweight API for 'Git'.

A light-weight, dependency-free, application programming interface (API) to access system-level 'Git' commands from within 'R'. Contains wrappers and defaults for common data science workflows as well as 'Zsh' plugin aliases. A generalized API syntax is also available. A system installation of 'Git' <https://git-scm.com/downloads> is required.

The gitr Package

GitHubversion CRANstatus R-CMD-check Codecov testcoverage Lifecycle:stable License:MIT

Overview

A light-weight, dependency-free, API to access system-level git commands from within R. It contains wrappers and defaults for common data science workflows as well as Z-shell and it’s plugins (see below). Generalized API syntax is also available. A system installation of git is required.

If you run into any issues/problems with gitr full documentation of the most recent release can be found at the pkgdown website. If the issue persists I encourage you to consult the issues page and, if appropriate, submit an issue and/or feature request.

Disclaimer

Use at own risk :smiley_cat:, however, PRs are encouraged for ideas that I’ve missed. The functionality contained in gitr are heavily influenced by my personal data science workflows and may not suit all users. However, if you have an idea that would make the package better, more widely usable, and/or efficient, please submit an issue or pull request.

Installation

The easiest way to install gitr is to install directly from CRAN:

install.packages("gitr")

Alternatively install the development version from GitHub:

remotes::install_github("stufield/gitr")

To install a specific tagged release, use:

remotes::install_github("stufield/[email protected]")

Load

library(gitr)

Example

Here are some basic examples of the functionality grouped by common actions:

Basics

git_version()
#> [1] "2.39.1"
git_current_br()
#> [1] "main"
git_default_br()
#> [1] "main"

Core Engine

(git("branch", "foo"))
#> Running git branch foo
#> $status
#> [1] 0
#> 
#> $stdout
#> [1] ""
#> 
#> $stderr
#> [1] ""

git("branch", "-av")$stdout |>
  cat(sep = "\n")
#> Running git branch -av 
#>   foo                          0c9ac89 Elaborate examples in README.Rmd
#> * main                         0c9ac89 Elaborate examples in README.Rmd
#>   remotes/origin/gh-pages      592df67 Built site for gitr: 0.0.0.9000@0c9ac89
#>   remotes/origin/main          0c9ac89 Elaborate examples in README.Rmd
#>   remotes/origin/prep-for-cran bb5a9bf Clean up URLs

git("branch", "-D", "foo")$stdout
#> Running git branch -D foo
#> [1] "Deleted branch foo (was 0c9ac89)."

Commits

get_commit_msgs(n = 3)
#> Running git log --format=%H -n 3
#> [[1]]
#> [1] "Elaborate examples in README.Rmd" ""                                
#> attr(,"sha")
#> [1] "0c9ac89"
#> attr(,"author")
#> [1] "[email protected]"
#> 
#> [[2]]
#> [1] "Update README.Rmd to include `git_tag_info()`" ""                                             
#> attr(,"sha")
#> [1] "d670c93"
#> attr(,"author")
#> [1] "[email protected]"
#> 
#> [[3]]
#> [1] "Git tag info no longer errors out" ""                                 
#> [3] "- informs user and returns NULL"   ""                                 
#> attr(,"sha")
#> [1] "45fc4c7"
#> attr(,"author")
#> [1] "[email protected]"
glog(5)
#> Running git log --oneline --graph --decorate -n 5 
#> * 0c9ac89 (HEAD -> main, origin/main) Elaborate examples in README.Rmd
#> * d670c93 Update README.Rmd to include `git_tag_info()`
#> * 45fc4c7 Git tag info no longer errors out
#> * 892e59f Ensure `git_sitrep()` doesn't return color non-interactive
#> * 2016312 Update '_pkgdown.yml' with new 'sha' topic
git_diffcommits()
#> Running git diff HEAD~2..HEAD~1 
#> diff --git a/README.Rmd b/README.Rmd
#> index 7feba10..8960baf 100644
#> --- a/README.Rmd
#> +++ b/README.Rmd
#> @@ -96,10 +96,6 @@ library(gitr)
#>  git_version()
#>  ```
#>  
#> -```{r sitrep}
#> -git_sitrep()
#> -```
#> -
#>  ```{r current}
#>  git_current_br()
#>  ```
#> @@ -112,6 +108,14 @@ git_default_br()
#>  glog()
#>  ```
#>  
#> +```{r sitrep}
#> +git_sitrep()
#> +```
#> +
#> +```{r tag-info}
#> +git_tag_info()
#> +```
#> +
#>  
#>  --------
#> 
git_reset_hard()
git_reset_soft()
git_uncommit()
git_unstage("DESCRIPTION")

SHA

trim_sha("d670c93733f3e1d7c95df7f61ebf6ca0476f14e3")
#> [1] "d670c93"

Tags

git_recent_tag()
#> Running git tag -n
#> [1] ""
git_tag_info()
#> ℹ No tags in repository ...

Situation Report

git_sitrep()
#> Using Git version: 2.39.1 
#> 
#> Current branch: main
#> Default branch: main 
#> 
#> Repo status:
#> Running git status -s 
#> 
#> 
#> Branches:
#> Running git branch -a 
#> * main
#>   remotes/origin/gh-pages
#>   remotes/origin/main
#>   remotes/origin/prep-for-cran
#> 
#> Local status:
#> ✓ OK
#> 
#> Upstream remotes: origin 
#> * main 0c9ac89 [origin/main] Elaborate examples in README.Rmd
#> 
#> Commit log: main 
#> Running git log --oneline --graph --decorate -n 5 
#> * 0c9ac89 (HEAD -> main, origin/main) Elaborate examples in README.Rmd
#> * d670c93 Update README.Rmd to include `git_tag_info()`
#> * 45fc4c7 Git tag info no longer errors out
#> * 892e59f Ensure `git_sitrep()` doesn't return color non-interactive
#> * 2016312 Update '_pkgdown.yml' with new 'sha' topic

ZSH-aliases available in gitr

aliasgit command
ga()git add
gst()git status
gss()git status -s
gau()git add -u
gaa()git add --all
gb()git branch
gba()git branch -a
gbd()git branch -d/-D
gdf()git diff <file>
gbnm()git branch --no-merged
gbmm()git branch --merged
gbr()git branch --remote
gac(), gcngit commit --no-verify --no-edit --amend
gcc()git commit
gco()git checkout
gcb()git checkout -b
gcm()git checkout git_default_br()
gcf()git config --list
gnuke()git reset --hard && git clean -dfx
gcmsg()git commit -m
gp()git push
gpu()git push -u
gpd()git push --dry-run
gpf()git push --force-with-lease
gpr()git pull --rebase --autostash -v
glog()git log --oneline --decorate --graph
gwip()git add -u && commit --no-verify -m "wip"
gclean()git clean -f -d
grm()git rm
grmc()git rm --cached
gsta()git stash
gstl()git stash list
gpop(),gstp()git stash pop
gstaa()git stash apply
gstd()git stash drop
gstc()git stash clear
gsts()git stash show --text
gtn()git tag -n
grba()git rebase --abort
grbc()git rebase --continue
grbs()git rebase --skip
grbm()git rebase git_default_br()
grv()git remote -v

Full list of ZSH-aliases

For general reference, here is a list of the available aliases via the git-plugin from Oh-My-Zsh.

See also Oh-My-Zsh for general installation.

Aliases

aliasgit command
gapagit add --patch
gavgit add --verbose
glogagit log --oneline --decorate --graph --all
gupgit pull --rebase
gupvgit pull --rebase -v
gupagit pull --rebase --autostash
gupavgit pull --rebase --autostash -v
gapgit apply
gaptgit apply --3way
gbda`git branch --no-color --mergedcommand grep -vE ^([+*]\s*($(git_main_branch)$(git_develop_branch))\s*$)command xargs git branch -d 2>/dev/null`
gblgit blame -b -w
gbsgit bisect
gbsbgit bisect bad
gbsggit bisect good
gbsrgit bisect reset
gbssgit bisect start
gcagit commit -v -a
gca!git commit -v -a --amend
gcan!git commit -v -a --no-edit --amend
gcans!git commit -v -a -s --no-edit --amend
gcamgit commit -a -m
gcsmgit commit -s -m
gcasgit commit -a -s
gcasmgit commit -a -s -m
gclgit clone --recurse-submodules
gcorgit checkout --recurse-submodules
gcdgit checkout $(git_develop_branch)
gcountgit shortlog -sn
gcpgit cherry-pick
gcpagit cherry-pick --abort
gcpcgit cherry-pick --continue
gcsgit commit -S
gcssgit commit -S -s
gcssmgit commit -S -s -m
gdcagit diff --cached
gdcwgit diff --cached --word-diff
gdctgit describe --tags \$(git rev-list --tags --max-count=1)
gdsgit diff --staged
gdtgit diff-tree --no-commit-id --name-only -r
gdupgit diff @{upstream}
gdwgit diff --word-diff
gfgit fetch
gfogit fetch origin
gfggit ls-files | grep
gggit gui citool
ggagit gui citool --amend
ggpurggu
ggpullgit pull origin \$(git_current_branch)
ggpushgit push origin \$(git_current_branch)
ggsupgit branch --set-upstream-to=origin/$(git_current_branch)
gpsupgit push --set-upstream origin \$(git_current_branch)
ghhgit help
gignoregit update-index --assume-unchanged
gignored`git ls-files -vgrep "^[[:lower:]]"`
git-svn-dcommit-pushgit svn dcommit && git push github \$(git_main_branch):svntrunk
glgit pull
glggit log --stat
glgpgit log --stat -p
glgggit log --graph
glggagit log --graph --decorate --all
glgmgit log --graph --max-count=10
glogit log --oneline --decorate
glolgit log --graph --pretty
glols="git log --graph --pretty%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat"
glod="git log --graph --pretty%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'"
glods="git log --graph --pretty%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short"
glola="git log --graph --pretty%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all"
gmgit merge
gmomgit merge origin/$(git_main_branch)
gmtlgit mergetool --no-prompt
gmtlvimgit mergetool --no-prompt --tool=vimdiff
gmumgit merge upstream/\$(git_main_branch)
gmagit merge --abort
gpf!git push --force
gpoatgit push origin --all && git push origin --tags
gpvgit push -v
grgit remote
gragit remote add
grbgit rebase
grbdgit rebase \$(git_develop_branch)
grbigit rebase -i
grbogit rebase --onto
grevgit revert
grhgit reset
grhhgit reset --hard
grohgit reset origin/\$(git_current_branch) --hard
grmvgit remote rename
grrmgit remote remove
grsgit restore
grsetgit remote set-url
grssgit restore --source
grstgit restore --staged
grtcd \$(git rev-parse --show-toplevel || echo .)
grugit reset --
grupgit remote update
gsbgit status -sb
gsdgit svn dcommit
gshgit show
gsigit submodule init
gspsgit show --pretty=short --show-signature
gsrgit svn rebase
gstugsta --include-untracked
gstallgit stash --all
gsugit submodule update
gswgit switch
gswcgit switch -c
gswmgit switch $(git_main_branch)
gswdgit switch $(git_develop_branch)
gtsgit tag -s
gtv`git tagsort -V`
gtlgtl(){ git tag --sort=-v:refname -n -l ${1}* }; noglob gtl
gunignoregit update-index --no-assume-unchanged
gunwip`git log -n 1grep -q -c "--wip--" && git reset HEAD~1`
glumgit pull upstream \$(git_main_branch)
gwchgit whatchanged -p --abbrev-commit --pretty=medium
gamgit am
gamcgit am --continue
gamsgit am --skip
gamagit am --abort
gamscpgit am --show-current-patch

LICENSE

Please note that this package package is released with a LICENSE. By using in this package you agree to abide by its terms.


Created by Rmarkdown (v2.20) and R version 4.2.2 (2022-10-31).

Metadata

Version

0.0.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows