add-and-commit: Stage and commit files

Description Usage Arguments Details Value Examples

Description

Stage files in preparation for a commit. And then commit them. Maybe even all at once! Convenience wrappers around add, commit, and status from git2r.

Usage

1
2
3
4
5
6
7
git_add(path, repo = ".", ...)

git_commit(message = NULL, repo = ".", ...)

git_ADD(repo = ".")

git_COMMIT(message = NULL, repo = ".")

Arguments

path

Character vector with file names or shell glob patterns that will matched against files in the repository's working directory. Each file that matches will be added to the index (either updating an existing entry or adding a new entry).

repo

Path to a Git repo. If unspecified, current working directory is checked to see if it is or is inside a Git repo.

...

Additional arguments to add or commit from git2r

message

The commit message.

Details

git_add adds the current content of files identified via path to the index, using add from git2r. These files are slated for inclusion in the next commit. What might go in ...? You could set 'force = TRUE' if you want to force add ignored files.

git_commit stores the current contents of the index in a new commit along with a message describing the changes. What might go in ...? Read up on the arguments to commit from git2r, which this wraps.

git_ADD says "JUST STAGE ALL THE THINGS." Use this when you want the next commit to reflect all new files, file deletions, and file modifications in your repo. Similar to the automatic staging behavior of workflow-oriented Git clients like GitHub Desktop. The intent is to emulate git add -A, which is equivalent to git add .; git add -u.

git_COMMIT says "JUST COMMIT ALL THE THINGS." Use this when you just want to commit the current state of your repo. It is git_ADD followed by git_commit. The intent is to emulate git add -A && git commit.

Value

Path to the associated Git repo.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
## conventional git add, status, commit
repo <- git_init(tempfile("githug-"))
owd <- setwd(repo)
writeLines("Are these girls real smart or real real lucky?", "max.txt")
git_add("max.txt")
git_status()
git_commit("Brains'll only get you so far and luck always runs out.")
git_status()
setwd(owd)

if (require(dplyr)) {
  ## are pipes silly here? perhaps ...
  repo <- tempfile("githug-") %>%
    git_init()
  owd <- setwd(repo)
  writeLines("Are these girls real smart or real real lucky?", "max.txt")
  "max.txt" %>%
    git_add() %>%
    git_status()
  git_commit("Brains'll only get you so far and luck always runs out.") %>%
    git_status()
  setwd(owd)
}

## THE SHOUTY COMMANDS
repo <- git_init(tempfile("GITHUG-"))
owd <- setwd(repo)
writeLines("Change me", "change-me")
writeLines("Delete me", "delete-me")
git_status()
git_add(c("change-me", "delete-me"))
git_status()
git_commit("initial")
write("OK", "change-me", append = TRUE)
file.remove("delete-me")
writeLines("Add me", "add-me")
git_status()
git_ADD()
git_status()
## TO DO: return here when commits and reset are wrapped
ccc <- git2r::commits()[[1]]
git2r::reset(ccc, "mixed")
git_status()
git_COMMIT("JUST DO IT.")
git_status()
setwd(owd)

jennybc/githug documentation built on May 19, 2019, 5:05 a.m.