Skip to content

Git Functions

⬅ Parent


git Installation

gitInstall

Install git if needed

Usage

gitInstall [ package ... ]

Installs the git binary

Arguments

  • package - Additional packages to install

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitEnsureSafeDirectory

When running git operations on a deployment host, at times

Usage

gitEnsureSafeDirectory [ --help ] directory

When running git operations on a deployment host, at times it's necessary to add the current directory (or a directory) to the git safe.directory directive.

This adds the directory passed to that directory in the local user's environment

Return Code: 0 - Success Return Code: 2 - Argument is not a valid directory Return Code: Other - git config error codes

Arguments

  • --help - Optional. Flag. Display this help.
  • directory - Required. Directory. The directory to add to the git safe.directory configuration directive

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

git Tags

gitTagDelete

Delete git tag locally and at origin

Usage

gitTagDelete [ --help ] [ tag ]

Delete git tag locally and at origin

Return Code: argument - Any stage fails will result in this exit code. Partial deletion may occur.

Arguments

  • --help - Optional. Flag. Display this help.
  • tag - The tag to delete locally and at origin

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitTagAgain

Remove a tag everywhere and tag again on the current

Usage

gitTagDelete [ tag ... ]

Remove a tag everywhere and tag again on the current branch

Return Code: 2 - Any stage fails will result in this exit code. Partial deletion may occur.

Arguments

  • tag - The tag to delete locally and remote

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitTagVersion

Generates a git tag for a build version, so v1.0d1,

Usage

gitTagVersion [ --suffix versionSuffix ] Tag version in git

Generates a git tag for a build version, so v1.0d1, v1.0d2, for version v1.0. Tag a version of the software in git and push tags to origin. If this fails it will output the installation log. When this tool succeeds the git repository contains a tag with the suffix and an index which represents the build index.

Default is: --suffix rc release candidate

  • d - for development
  • s - for staging
  • rc - for release candidate

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Environment

  • BUILD_VERSION_SUFFIX - String. Default suffix used in gitTagVersion
  • String. Version suffix to use as a default. If not specified the default is rc.
  • BUILD_MAXIMUM_TAGS_PER_VERSION - PositiveInteger. Number of versions tags (d0, d1, d2, etc.) to look for before giving up in gitTagVersion
  • Integer. Number of integers to attempt to look for when incrementing.

gitVersionList

Fetches a list of tags from git and filters those

Usage

gitVersionList

Fetches a list of tags from git and filters those which start with v and a digit and returns them sorted by version correctly.

Return Code: 1 - If the .git directory does not exist Return Code: 0 - Success

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitVersionLast

Get the last reported version.

Usage

gitVersionLast [ ignorePattern ]

Get the last reported version.

Arguments

  • ignorePattern - Optional. Specify a grep pattern to ignore; allows you to ignore current version

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

veeGitTag

Given a tag in the form "1.1.3" convert it to

Usage

veeGitTag

Given a tag in the form "1.1.3" convert it to "v1.1.3" so it has a character prefix "v" Delete the old tag as well

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

git Branches

gitBranchExists

Does a branch exist locally or remotely?

Usage

gitBranchExists branch ... [ --help ]

Does a branch exist locally or remotely? Return Code: 0 - All branches passed exist Return Code: 1 - At least one branch does not exist locally or remotely

Arguments

  • branch ... - String. Required. List of branch names to check.
  • --help - Optional. Flag. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitBranchExistsRemote

Does a branch exist remotely?

Usage

gitBranchExistsRemote branch ...

Does a branch exist remotely? Return Code: 0 - All branches exist on the remote Return Code: 1 - At least one branch does not exist remotely

Arguments

  • branch ... - String. Required. List of branch names to check.
  • --help - Optional. Flag. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitBranchExistsLocal

Does a branch exist locally?

Usage

gitBranchExistsLocal branch ...

Does a branch exist locally? Return Code: 0 - All branches exist Return Code: 1 - At least one branch does not exist locally

Arguments

  • branch ... - String. Required. List of branch names to check.
  • --help - Optional. Flag. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitBranchify

Check out a branch with the current version and optional

Arguments

  • --help - Optional. Flag. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Environment

  • BUILD_BRANCH_FORMAT

gitBranchMergeCurrent

Merge the current branch with another, push to remote, and

Usage

gitBranchMergeCurrent branch [ --skip-ip ] [ --comment ] [ --help ]

Merge the current branch with another, push to remote, and then return to the original branch.

Arguments

  • branch - String. Required. Branch to merge the current branch with.
  • --skip-ip - Boolean. Optional. Do not add the IP address to the comment.
  • --comment - String. Optional. Comment for merge commit.
  • --help - Optional. Flag. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

git Development

gitCommitHash

Get the commit hash

Usage

gitCommitHash

Get the commit hash

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitCommit

Commits all files added to git and also update release

Usage

gitCommit [ --last ] [ -- ] [ comment ... ]

Commits all files added to git and also update release notes with comment

Comment wisely. Does not duplicate comments. Check your release notes.

Example:

Arguments

  • --last - Optional. Flag. Append last comment
  • -- - Optional. Flag. Skip updating release notes with comment.
  • --help - Optional. Flag. I need somebody.
  • comment - Optional. Text. A text comment for release notes and describing in general terms, what was done for a commit message.

Examples

c last
c --last
c --

... are all equivalent.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitMainly

Return Code: 1 - Already in main, staging, or HEAD,

Usage

gitMainly

Return Code: 1 - Already in main, staging, or HEAD, or git merge failed Return Code: 0 - git merge succeeded Merge staging and main branches of a git repository into the current branch.

Will merge origin/staging and origin/main after doing a --pull for both of them

Current repository should be clean and have no modified files.

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitFindHome

Finds .git directory above or at startingDirectory

Usage

gitFindHome startingDirectory

Finds .git directory above or at startingDirectory

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitHookTypes

List current valid git hook types

Usage

gitHookTypes

List current valid git hook types Hook types: - pre-commit - pre-push - pre-merge-commit - pre-rebase - pre-receive - update - post-update - post-commit

Arguments

  • none

Sample Output

lines:gitHookType

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitInstallHook

Install the most recent version of this hook and RUN

Usage

gitInstallHook [ --application applicationHome ] [ --copy ] hook

Install the most recent version of this hook and RUN IT in place if it has changed. You should ONLY run this from within your hook, or provide the --copy flag to just copy. When running within your hook, pass additional arguments so they can be preserved:

gitInstallHook --application "$myHome" pre-commit "$@" || return $?

Return Code: 0 - the file was not updated Return Code: 1 - Environment error Return Code: 2 - Argument error

Arguments

  • hook - A hook to install. Maps to git-hook internally. Will be executed in-place if it has changed from the original.
  • --application - Optional. Directory. Path to application home.
  • --copy - Optional. Flag. Do not execute the hook if it has changed.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Environment

  • BUILD-HOME - The default application home directory used for .git and build hooks.

gitInstallHooks

Install one or more git hooks from Zesk Build hooks.

Usage

gitInstallHooks [ --copy ] [ --verbose ] [ --application home ] [ hookName ]

Install one or more git hooks from Zesk Build hooks. Zesk Build hooks are named git-hookName.sh in bin/hooks/ so git-pre-commit.sh will be installed as the pre-commit hook for git.

Hook types: - pre-commit - pre-push - pre-merge-commit - pre-rebase - pre-receive - update - post-update - post-commit

Arguments

  • --copy - Flag. Optional. Copy the hook but do not execute it.
  • --verbose - Flag. Optional. Be verbose about what is done.
  • --application home - Directory. Optional. Set the application home directory to this prior to looking for hooks.
  • hookName - String. Optional. A hook or hook names to install. See gitHookTypes

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

git History

gitRemoveFileFromHistory

Has a lot of caveats

Usage

gitRemoveFileFromHistory

Has a lot of caveats

gitRemoveFileFromHistory path/to/file

usually have to git push --force

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

git Working Tree State

gitRepositoryChanged

Return Code: 1 - the repo has NOT been modified

Usage

gitRepositoryChanged

Return Code: 1 - the repo has NOT been modified Return Code: 0 - the repo has been modified

Has a git repository been changed from HEAD?

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitShowChanges

Return Code: 0 - the repo has been modified

Usage

gitShowChanges

Return Code: 0 - the repo has been modified Return Code: 1 - the repo has NOT bee modified

Show changed files from HEAD

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitShowStatus

Return Code: 0 - the repo has been modified

Usage

gitShowStatus

Return Code: 0 - the repo has been modified Return Code: 1 - the repo has NOT bee modified

Show changed files from HEAD with their status prefix character:

  • ' ' = unmodified
  • M = modified
  • A = added
  • D = deleted
  • R = renamed
  • C = copied
  • U = updated but unmerged

(See man git for more details on status flags)

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitInsideHook

Are we currently inside a git hook?

Usage

gitInsideHook

Are we currently inside a git hook?

Tests non-blank strings in our environment.

Return Code: 0 - We are, semantically, inside a git hook Return Code: 1 - We are NOT, semantically, inside a git hook

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Environment

  • GIT_EXEC_PATH - Must be set to pass
  • GIT_INDEX_FILE - Must be set to pass

gitRemoteHosts

List remote hosts for the current git repository

Usage

gitRemoteHosts

List remote hosts for the current git repository Parses user@host:path/project.git and extracts host

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitCurrentBranch

Get the current branch name

Usage

gitCurrentBranch

Get the current branch name

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitHasAnyRefs

Does git have any tags?

Usage

gitHasAnyRefs

Does git have any tags? May need to git pull --tags, or no tags exist.

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

git pre-commit hook

gitPreCommitSetup

Set up a pre-commit hook and create a cache of

Usage

gitPreCommitSetup

Set up a pre-commit hook and create a cache of our files by extension. Return code: 0 - One or more files are available as part of the commit Return code: 1 - Error, or zero files are available as part of the commit

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitPreCommitHeader

Output a display for pre-commit files changed

Usage

gitPreCommitHeader [ extension ]

Output a display for pre-commit files changed

Arguments

  • extension - Optional. String. Extension to display

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitPreCommitExtensionList

List the extensions available

Usage

gitPreCommitExtensionList [ --help ]

List the extensions available

Writes to standard output

String. One per line.

Arguments

  • --help - Optional. Flag. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitPreCommitHasExtension

Does this commit have the following file extensions?

Usage

gitPreCommitHasExtension [ extension ]

Does this commit have the following file extensions? Return code: 0 - if all extensions are present Return code: 1 - if any extension is not present

Arguments

  • extension - Optional. String. Extension to check. Use ! for blank extension and @ for all extensions. Can specify one or more.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitPreCommitListExtension

List the file(s) of an extension

Usage

gitPreCommitListExtension [ extension ] [ --help ]

List the file(s) of an extension

Writes to standard output

File. One per line.

Arguments

  • extension - Optional. String. Extension to list. Use ! for blank extension and @ for all extensions. Can specify one or more.
  • --help - Optional. Flag. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

gitPreCommitCleanup

Clean up after our pre-commit (deletes cache directory)

Usage

gitPreCommitCleanup [ --help ]

Clean up after our pre-commit (deletes cache directory)

Arguments

  • --help - Optional. Flag. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error