Skip to content

Git Functions

Zesk Build provides pre-commit functionality and many tools to aid with git development.


Installation

gitInstall

Install git if needed

Usage

gitInstall [ package ]

Installs the git binary

Location: bin/build/tools/git.sh

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

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 0 - Success
  • 2 - Argument is not a valid directory
  • Other - git config error codes

Tagging

gitTagDelete

Delete git tag locally and at origin

Usage

gitTagDelete [ --help ] [ tag ]

Delete git tag locally and at origin

Location: bin/build/tools/git.sh

Arguments

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

Return codes

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

gitTagAgain

Remove a tag everywhere and tag again on the current

Usage

gitTagAgain [ tag ]

Remove a tag everywhere and tag again on the current branch

Location: bin/build/tools/git.sh

Arguments

  • tag - String. Optional. The tag to tag again.

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 ]

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.

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

Location: bin/build/tools/git.sh

Return codes

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

Environment

gitVersionList

Fetches a list of tags from git and filters those

Usage

gitVersionList [ --help ]

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

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 1 - If the .git directory does not exist
  • 0 - Success

gitVersionLast

Get the last reported version.

Usage

gitVersionLast [ ignorePattern ] [ --help ]

Get the last reported version.

Location: bin/build/tools/git.sh

Arguments

  • ignorePattern - Optional. String. Specify a grep pattern to ignore; allows you to ignore current version
  • --help - Flag. Optional. Display this help.

Return codes

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

gitTagVee

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

Usage

gitTagVee

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

Location: bin/build/tools/git.sh

Arguments

  • none

Return codes

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

Branches

gitBranchExists

Does a branch exist locally or remotely?

Usage

gitBranchExists branch ... [ --help ]

Does a branch exist locally or remotely?

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 0 - All branches passed exist
  • 1 - At least one branch does not exist locally or remotely

gitBranchExistsRemote

Does a branch exist remotely?

Usage

gitBranchExistsRemote branch ... [ --help ]

Does a branch exist remotely?

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 0 - All branches exist on the remote
  • 1 - At least one branch does not exist remotely

gitBranchExistsLocal

Does a branch exist locally?

Usage

gitBranchExistsLocal branch ... [ --help ]

Does a branch exist locally?

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 0 - All branches exist
  • 1 - At least one branch does not exist locally

gitBranchify

Check out a branch with the current version and optional

Arguments

  • --help - Flag. Optional. 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.

Location: bin/build/tools/git.sh

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 - Flag. Optional. Display this help.

Return codes

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

Development

gitCommit

Commits all files added to git and also update release

Usage

gitCommit [ --last ] [ -- ] [ --help ] [ 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:

Location: bin/build/tools/git.sh

Arguments

  • --last - Flag. Optional. Append last comment
  • -- - Flag. Optional. Skip updating release notes with comment.
  • --help - Flag. Optional. I need somebody.
  • comment - Text. Optional. 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

Merge staging and main branches of a git repository into

Usage

gitMainly

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.

Location: bin/build/tools/git.sh

Arguments

  • none

Return codes

  • 1 - Already in main, staging, or HEAD, or git merge failed
  • 0 - git merge succeeded

gitFindHome

Find git home directory

Usage

gitFindHome [ startingDirectory ]

Finds .git directory above or at startingDirectory.

Location: bin/build/tools/git.sh

Arguments

  • startingDirectory - Directory. Optional.

Return codes

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

Hooks

gitHookTypes

List current valid git hook types

Usage

gitHookTypes [ --help ]

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

Location: bin/build/tools/git.sh

Arguments

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

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 ] [ --copy ] [ hook ] [ --help ]

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 $?

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 0 - the file was not updated
  • 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 ] [ --help ]

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

Location: bin/build/tools/git.sh

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
  • --help - Flag. Optional. Display this help.

Return codes

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

See Also

gitInsideHook

Are we currently inside a git hook?

Usage

gitInsideHook

Are we currently inside a git hook?

Tests non-blank strings in our environment.

Location: bin/build/tools/git.sh

Arguments

  • none

Return codes

  • 0 - We are, semantically, inside a git hook
  • 1 - We are NOT, semantically, inside a git hook

Environment

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

History

gitRemoveFileFromHistory

Has a lot of caveats

Usage

gitRemoveFileFromHistory

Has a lot of caveats

gitRemoveFileFromHistory path/to/file

usually have to git push --force

Location: bin/build/tools/git.sh

Arguments

  • none

Return codes

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

Working Tree State

gitRepositoryChanged

Has a git repository been changed from HEAD?

Usage

gitRepositoryChanged

Has a git repository been changed from HEAD?

Location: bin/build/tools/git.sh

Arguments

  • none

Return codes

  • 1 - the repo has NOT been modified
  • 0 - the repo has been modified

gitShowChanges

Show changed files from HEAD

Usage

gitShowChanges [ --help ]

Show changed files from HEAD

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 0 - the repo has been modified
  • 1 - the repo has NOT bee modified

gitShowStatus

Show changed files from HEAD with their status prefix character:

Usage

gitShowStatus [ --help ]

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)

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 0 - the repo has been modified
  • 1 - the repo has NOT bee modified

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

Location: bin/build/tools/git.sh

Arguments

  • none

Return codes

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

gitCommitHash

Get the commit hash

Usage

gitCommitHash

Get the commit hash

Location: bin/build/tools/git.sh

Arguments

  • none

Return codes

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

gitCurrentBranch

Get the current branch name

Usage

gitCurrentBranch [ --help ]

Get the current branch name

Location: bin/build/tools/git.sh

Arguments

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

Return codes

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

gitHasAnyRefs

Does git have any tags?

Usage

gitHasAnyRefs [ --help ]

Do any tags exist at all in git? May need to git pull --tags, or no tags exist.

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 0 - At least one tag exists
  • 1 - No tags exist

pre-commit hook Tools

gitPreCommitSetup

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

Usage

gitPreCommitSetup [ --help ]

Set up a pre-commit hook and create a cache of our files by extension.

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 0 - One or more files are available as part of the commit
  • 1 - Error, or zero files are available as part of the commit

See Also

gitPreCommitHeader

Output a display for pre-commit files changed.

Usage

gitPreCommitHeader [ extension ] [ --help ]

Output a display for pre-commit files changed.

Location: bin/build/tools/git.sh

Arguments

  • extension - String. Optional. Extension to display
  • --help - Flag. Optional. Display this help.

Return codes

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

gitPreCommitExtensionList

List the extensions available.

Usage

gitPreCommitExtensionList [ --help ]

List the extensions available.

Location: bin/build/tools/git.sh

Arguments

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

Writes to standard output

String. One per line.

Return codes

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

gitPreCommitHasExtension

Does this commit have the following file extensions?

Usage

gitPreCommitHasExtension [ extension ] [ --help ]

Does this commit have the following file extensions?

Location: bin/build/tools/git.sh

Arguments

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

Return codes

  • 0 - if all extensions are present
  • 1 - if any extension is not present

gitPreCommitListExtension

List the file(s) of an extension.

Usage

gitPreCommitListExtension [ extension ] [ --help ]

List the file(s) of an extension.

Location: bin/build/tools/git.sh

Arguments

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

Writes to standard output

File. One per line.

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)

Location: bin/build/tools/git.sh

Arguments

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

Return codes

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

🛠️ Tools · ⬅ Top