Git Functions
git Installation
gitInstall
Install git if needed
Usage
gitInstall [ package ]
Installs the git binary
Arguments
package- Additional packages to install
Return codes
0- Success1- Environment error2- 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
Arguments
--help- Flag. Optional. Display this help.directory- Directory. Required. The directory to add to thegitsafe.directoryconfiguration directive
Return codes
0- Success2- Argument is not a valid directoryOther- git config error codes
git Tags
gitTagDelete
Delete git tag locally and at origin
Usage
gitTagDelete [ --help ] [ tag ]
Delete git tag locally and at origin
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
Arguments
tag- String. Optional. The tag to tag again.
Return codes
0- Success1- Environment error2- 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
Return codes
0- Success1- Environment error2- Argument error
Environment
- {SEE:BUILD_VERSION_SUFFIX.sh} - String. Version suffix to use as a default. If not specified the default is
rc. - {SEE:BUILD_MAXIMUM_TAGS_PER_VERSION.sh} - Integer. Number of integers to attempt to look for when incrementing.
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.
Arguments
--help- Flag. Optional. Display this help.
Return codes
1- If the.gitdirectory does not exist0- Success
gitVersionLast
Get the last reported version.
Usage
gitVersionLast [ ignorePattern ] [ --help ]
Get the last reported version.
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- Success1- Environment error2- 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
Arguments
- none
Return codes
0- Success1- Environment error2- Argument error
git Branches
gitBranchExists
Does a branch exist locally or remotely?
Usage
gitBranchExists branch ... [ --help ]
Does a branch exist locally or remotely?
Arguments
branch ...- String. Required. List of branch names to check.--help- Flag. Optional. Display this help.
Return codes
0- All branches passed exist1- 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?
Arguments
branch ...- String. Required. List of branch names to check.--help- Flag. Optional. Display this help.
Return codes
0- All branches exist on the remote1- At least one branch does not exist remotely
gitBranchExistsLocal
Does a branch exist locally?
Usage
gitBranchExistsLocal branch ... [ --help ]
Does a branch exist locally?
Arguments
branch ...- String. Required. List of branch names to check.--help- Flag. Optional. Display this help.
Return codes
0- All branches exist1- 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- Success1- Environment error2- 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- Flag. Optional. Display this help.
Return codes
0- Success1- Environment error2- Argument error
git Development
gitCommitHash
Get the commit hash
Usage
gitCommitHash
Get the commit hash
Arguments
- none
Return codes
0- Success1- Environment error2- Argument error
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:
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- Success1- Environment error2- Argument error
gitMainly
Merge
stagingandmainbranches 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.
Arguments
- none
Return codes
1- Already in main, staging, or HEAD, or git merge failed0- git merge succeeded
gitFindHome
Finds
.gitdirectory above or atstartingDirectory
Usage
gitFindHome [ startingDirectory ]
Finds .git directory above or at startingDirectory
Arguments
startingDirectory- Directory. Optional.
Return codes
0- Success1- Environment error2- Argument error
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
Arguments
--help- Flag. Optional. Display this help.
Sample Output
lines:gitHookType
Return codes
0- Success1- Environment error2- 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 $?
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 togit-hookinternally. 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 updated1- Environment error2- Argument error
Environment
- BUILD-HOME - The default application home directory used for
.gitand 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
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. SeegitHookTypes--help- Flag. Optional. Display this help.
Return codes
0- Success1- Environment error2- 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- Success1- Environment error2- Argument error
git Working Tree State
gitRepositoryChanged
Has a git repository been changed from HEAD?
Usage
gitRepositoryChanged
Has a git repository been changed from HEAD?
Arguments
- none
Return codes
1- the repo has NOT been modified0- the repo has been modified
gitShowChanges
Show changed files from HEAD
Usage
gitShowChanges [ --help ]
Show changed files from HEAD
Arguments
--help- Flag. Optional. Display this help.
Return codes
0- the repo has been modified1- 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)
Arguments
--help- Flag. Optional. Display this help.
Return codes
0- the repo has been modified1- the repo has NOT bee modified
gitInsideHook
Are we currently inside a git hook?
Usage
gitInsideHook
Are we currently inside a git hook? Tests non-blank strings in our environment.
Arguments
- none
Return codes
0- We are, semantically, inside a git hook1- 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
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- Success1- Environment error2- Argument error
gitCurrentBranch
Get the current branch name
Usage
gitCurrentBranch [ --help ]
Get the current branch name
Arguments
--help- Flag. Optional. Display this help.
Return codes
0- Success1- Environment error2- 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.
Arguments
--help- Flag. Optional. Display this help.
Return codes
0- At least one tag exists1- No tags exist
git pre-commit hook
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.
Arguments
--help- Flag. Optional. Display this help.
Return codes
0- One or more files are available as part of the commit1- Error, or zero files are available as part of the commit
gitPreCommitHeader
Output a display for pre-commit files changed.
Usage
gitPreCommitHeader [ extension ] [ --help ]
Output a display for pre-commit files changed.
Arguments
extension- String. Optional. Extension to display--help- Flag. Optional. Display this help.
Return codes
0- Success1- Environment error2- Argument error
gitPreCommitExtensionList
List the extensions available.
Usage
gitPreCommitExtensionList [ --help ]
List the extensions available.
Arguments
--help- Flag. Optional. Display this help.
Writes to standard output
String. One per line.
Return codes
0- Success1- Environment error2- Argument error
gitPreCommitHasExtension
Does this commit have the following file extensions?
Usage
gitPreCommitHasExtension [ extension ] [ --help ]
Does this commit have the following file extensions?
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 present1- 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.
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- Success1- Environment error2- 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- Flag. Optional. Display this help.
Return codes
0- Success1- Environment error2- Argument error