The git module implements functions for interacting with git repositories in the local file system.
Function | Purpose |
---|---|
git_clone() | Clone a git repository |
git_commit() | Commit a change to the current branch |
git_branch_new() | Create a new branch |
git_branch_get_current() | Get the name of the current branch |
git_branch_get_commits() | List the commits in a branch |
git_branch_checkout() | Change the current branch |
git_merge() | Merge one branch into another one |
git_push() | Push a branch to a remote |
git_remote_get() | Get the URL of a remote |
Clone a git repository
git_clone "$source" "$destination"
The git_clone()
function clones the repository specified by $source
into the path specified
by $destination
. The source repository may be reachable via any protocol that is understood by
git. The path specified in $destination
must be on a local file system. It is not necessary
that the destination path exists, however the executing user must have sufficient permissions to
create the path, if it does not exist.
Return value | Meaning |
---|---|
0 | The repository was successfully cloned |
1 | The repository could not be cloned |
git_clone()
does not read from standard input.
git_clone()
does not write to standard output.
If an error occurs, git_clone()
will write an error message to standard error. The message
that is written includes the standard output and standard error from the git command that was
invoked by git_clone()
.
Commit a change to the current branch
git_commit "$repository" "$message"
The git_commit()
function commits the changes that are staged in the repository specified by
$repository
to the repository's current branch. The commit message will be set to the value
passed in $message
.
Return value | |
---|---|
0 | The staged changes were successfully committed |
1 | The changes could not be committed |
This function does not read from standard input.
This function does not write to standard output.
In case of an error, git_commit()
will write an error message to standard error. The message
that is written includes the standard output and standard error from the git command that was
invoked by git_commit()
.
Create a new branch
git_branch_new "$repository" "$branch"
The git_branch_new()
function creates a new branch with name $branch
in the repository
specified by $repository
.
Return value | Meaning |
---|---|
0 | The branch was created successfully |
1 | The branch could not be created |
This function does not read from standard input.
This function does not write to standard output.
In case of an error, git_branch_new()
will write an error message to standard error. The message
that is written includes the standard output and standard error from the git command that was
invoked by git_branch_new()
.
Get the name of the current branch
git_branch_get_current "$repository"
The git_branch_get_current()
function writes the name of the working branch of the repository
specified by $repository
to standard output. The repository must be located in the local file
system and must not be a bare repository.
Return value | Meaning |
---|---|
0 | The branch name was written to standard output |
1 | The branch name could not be determined |
This function does not read from standard input.
On success, the name of the repository's working branch is written to standard output. Otherwise, no data is written to standard output.
In case of an error, git_branch_get_current()
will write an error message to standard error.
List the commits in a branch
git_branch_get_commits "$repository" "$branch"
The git_branch_get_commits()
function lists the commits in the branch branch
of the
repository identified by repository
. For each commit in the branch, it will write one
line containing the commit hash, date, and email address of the committer to standard
output.
Commits are listed in reverse chronological order starting with the newest commit.
Return value | Meaning |
---|---|
0 | Success |
1 | Could not lookup the branch history |
This function does not read from standard input.
On success, all commits that are part of the branch will be written to standard output, one commit per line. Each line contains the commit hash, date, and committer email address, separated by single-width space characters. The date is output in strict ISO 8601 format. Commits are output in reverse chronological order starting with the newest commit.
This function does not write to standard error.
Change the current branch
git_branch_checkout "$repository" "$branch"
The git_branch_checkout()
function changes the working branch of the repository specified by
$repository
to the branch specified by $branch
. The repository must be located in the local
file system. If $branch
was omitted, the master
branch will be checked out.
Return value | Meaning |
---|---|
0 | The working branch was successfully changed |
1 | The working branch could not be changed |
This function does not read from standard input.
This function does not write to standard output.
In case of an error, git_branch_checkout()
will write an error message to standard error. The message
that is written includes the standard output and standard error from the git command that was invoked
by git_branch_checkout()
.
Merge one branch into another one
git_merge "$repository" "$source" "$destination"
The git_merge()
function merges the branch $source
of the repository $repository
into the branch
$destination
of the same repository. If $destination
was omitted, $source
will be merged into the
working branch of the repository.
Return value | Meaning |
---|---|
0 | The merge operation was successful |
1 | The merge could not be performed |
This function does not read from standard input.
This function does not write to standard output.
In case of an error, git_merge()
will write an error message to standard error. The message
that is written includes the standard output and standard error from the git command that was
invoked by git_merge()
.
Push a branch to a remote
git_push "$repository" "$branch" "$remote"
The git_push()
function pushes the branch $branch
of the repository $repository
to the
remote $remote
. If $remote
was omitted, the branch will be pushed to the remote origin
.
If $branch
was omitted, the working branch will be pushed.
Return value | Meaning |
---|---|
0 | The branch was pushed successfully |
1 | The branch could not be pushed |
This function does not read from standard input.
This function does not write to standard output.
In case of an error, git_push()
will write an error message to standard error. The message that
is written will include the standard output and standard error of the git command that was invoked
by git_push()
.
Get the URL of a remote
git_remote_get "$repository" "$remote"
The git_remote_get()
function determines the URL of the remote $remote
of the repository
$repository
and writes it to standard output.
Return value | Meaning |
---|---|
0 | The URL of the remote was written to standard output |
1 | The URL of the remote could not be determined |
This function does not read from standard input.
On success, the URL of the remote is written to standard output. Otherwise, no data is written to standard output.
In case of an error, git_remote_get()
will write an error message to standard error.