Skip to content

Commit c17b676

Browse files
author
Lars Schneider
committed
update to v1.7.19
1 parent d725d2b commit c17b676

36 files changed

+1067
-527
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Enterprise Config for Git
22

3-
A painless Git setup with an easy way to share Git configs and scripts within a company using GitHub Enterprise or any similar on-premise Git hosting service.
3+
A painless Git setup with an easy way to share Git configs and scripts within a company using GitHub Enterprise.
44

5-
_Enterprise Config for Git_ adds a new Git setup command (e.g. `git mycompany`) to your Git config (via Git config alias) that configures a developer machine. The setup command checks the installed Git version, ensures Git LFS is installed properly, configures the user name and email based on the GitHub Enterprise profile, and configures the Git credential helper with a GitHub Enterprise token. It also adds an easy way to distribute company Git configs (e.g. [Git push protection](./config.include#L25-L39)) and Git helper scripts (e.g. [`git adsk clone`](./clone.sh)).
5+
_Enterprise Config for Git_ adds a new Git setup command (e.g. `git mycompany`) to your Git config (via Git config alias) that configures a developer machine. The setup command checks the installed Git version, ensures Git LFS is installed properly, configures the user name and email based on the GitHub Enterprise profile, and configures the Git credential helper with a GitHub Enterprise token. It also adds an easy way to distribute company Git configs (e.g. [Git push protection](./config.include#L25-L35)) and Git helper scripts (e.g. [`git adsk clone`](./clone.sh)).
66

77
_Enterprise Config for Git_ supports Windows, Mac and Linux and a great number of shells such as BASH, ZSH, DASH, cmd.exe, and PowerShell.
88

@@ -11,9 +11,12 @@ Please find more details about _Enterprise Config for Git_ in the corresponding
1111

1212
## Getting Started
1313

14-
In order to use _Enterprise Config for Git_ you need to fork it to your GitHub Enterprise instance (ensure that every engineer has read access) and adjust it for your company:
15-
* Define the [name of the setup command](./config.include#L51) for your company
16-
* Define your _Enterprise Config for Git_ [constants](./enterprise.constants)
14+
In order to use _Enterprise Config for Git_ you need to fork it to your GitHub Enterprise instance and adjust it for your company:
15+
* Define the [name of the setup command](./config.include#L46) for your company
16+
* Set the [GitHub Enterprise server](./setup.sh#L8) (e.g. `github.mycompany.com`)
17+
* Set _Enterprise Config for Git_ [organization/repository of your fork](./setup.sh#L9) on your GitHub Enterprise server (e.g. `tools/enterprise-config`). Please ensure every engineer has read access.
18+
* Define your [contact in case of errors](./setup.sh#L16)
19+
* Register an [OAuth application](https://developer.github.com/v3/oauth/) on your GitHub Enterprise server and setup the _Enterprise Config for Git_ [client ID and secret](./setup.sh#L12-L13).
1720
* Configure your desired [company email pattern](./lib/setup_helpers.sh#L84).
1821
* Create a production branch based on the master branch.
1922

checkout.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bash
2-
#
3-
# Checkout a branch and update submodules accordingly
4-
#
5-
# Usage: git <KIT_ID> checkout <branch>
6-
#
2+
#/
3+
#/ Checkout a branch and update submodules accordingly
4+
#/
5+
#/ Usage: git $KIT_ID checkout <branch>
6+
#/
77
set -e
88

9-
git checkout $@
9+
git checkout "$@"
1010
git submodule update --init --recursive

clean-checkout.sh

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env bash
2-
#
3-
# Clean checkout of a branch/tag/commit including all submodules.
4-
# Attention: This is going to delete all local changes!
5-
#
6-
# Usage: git <KIT_ID> clean-checkout <options> <branch>
7-
#
8-
# <options> will be passed to the git clean command, see git-clean reference
9-
# for available options (-d --force --quiet are passed by default)
10-
# <branch> is expected to be the last argument
11-
#
12-
# Example: git ask clean-checkout master
13-
#
2+
#/
3+
#/ Clean checkout of a branch/tag/commit including all submodules.
4+
#/ Attention: This is going to delete all local changes!
5+
#/
6+
#/ Usage: git $KIT_ID clean-checkout <options> <branch>
7+
#/
8+
#/ <options> will be passed to the git clean command, see git-clean reference
9+
#/ for available options (-d --force --quiet are passed by default)
10+
#/ <branch> is expected to be the last argument
11+
#/
12+
#/ Example: git ask clean-checkout master
13+
#/
1414
set -e
1515

1616
# check if there is at least one argument passed to the command
@@ -19,30 +19,46 @@ if [ $# -lt 1 ]; then
1919
exit 1
2020
fi
2121

22+
function execute_with_retry {
23+
COMMAND=$1
24+
RETRIES=7 # longest continuous wait should be 64s (2**6)
25+
COUNT=1 # first try after 4s, if needed
26+
RET=1 # make command overwrite this
27+
while [ $COUNT -lt $RETRIES ]; do
28+
set +e
29+
$COMMAND
30+
RET=$?
31+
set -e
32+
if [ $RET -eq 0 ]; then
33+
break
34+
fi
35+
COUNT=$((COUNT+1))
36+
DELAY=$((2**COUNT))
37+
sleep $DELAY
38+
done
39+
if [ $RET -gt 0 ]; then
40+
echo "'$COMMAND' failed with exit code '$RET'"
41+
exit $RET
42+
fi
43+
}
44+
45+
2246
# read branch and options from the arguments, branch is expected to be the last argument
2347
REF=${!#}
2448
OPTIONS=${@:1:$#-1}
2549

2650
# fetch latest changes from all remotes
27-
git fetch --all --force
28-
29-
# check if the requested ref (branch/tag/commit) exists
30-
if [ -z "$(git cat-file -t $REF)" ]; then
31-
echo "Specified ref '$REF' not found"
32-
exit 1
33-
fi
34-
35-
# sync submodules in case submodule URLs have changed
36-
git submodule sync --recursive
51+
# cleanup all refs that no longer exist in the remote:
52+
# * could avoid name collisions on case insensitive file systems
3753

38-
# reset repo to have a clean state that enables a checkout in the next step
39-
git reset --hard HEAD
54+
execute_with_retry "git fetch --all --force --prune"
4055

4156
# checkout branch and update submodules
4257
git checkout --force $REF
43-
git submodule update --force --init --recursive
58+
git submodule sync --recursive
59+
execute_with_retry "git submodule update --force --init --recursive"
4460

4561
# clean up repo and submodules
4662
git clean -d --force --quiet $OPTIONS
47-
git submodule foreach git clean -d --force --quiet $OPTIONS
48-
git submodule foreach git reset --hard HEAD
63+
git submodule foreach --recursive git clean -d --force --quiet $OPTIONS
64+
git submodule foreach --recursive git reset --hard HEAD

clone-no-lfs.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
#/
3+
#/ Clone a Git repository without downloading any Git LFS content.
4+
#/
5+
#/ Usage: git $KIT_ID clone-no-lfs <repository URL> [<target directory>]
6+
#/
7+
8+
GIT_LFS_SKIP_SMUDGE=1 git clone --recursive "$@"

clone.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env bash
2-
#
3-
# Clone Git repositories and download Git LFS files in parallel.
4-
# See more info here: https://github.com/github/git-lfs/issues/931
5-
#
6-
# Usage: git <KIT_ID> clone <repository URL> [<target directory>]
7-
#
8-
set -e
2+
#/
3+
#/ Fast clone a repository with Git LFS files and submodules.
4+
#/
5+
#/ Usage: git $KIT_ID clone <repository URL> [<target directory>]
6+
#/
97

10-
git-lfs clone --recursive $@
8+
# c.f. https://github.com/github/git-lfs/issues/931
9+
git-lfs clone --recursive "$@"

config.include

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
# c.f. https://groups.google.com/forum/#!topic/git-for-windows/9WrSosaa4A8
44
fscache = true
55

6+
# Enable long path support for Windows (no effect on OS X/Linux)
7+
# Git uses the proper API to create long paths on Windows. However, many
8+
# Windows applications use an outdated API that only support paths up to a
9+
# length of 260 characters. As a result these applications would not be able to
10+
# work with the longer paths properly. Keep that in mind if you run into path
11+
# trouble!
12+
# c.f. https://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
13+
longpaths = true
14+
615
[help]
716
autocorrect = 1
817

@@ -15,13 +24,6 @@
1524
[submodule]
1625
fetchJobs = 0
1726

18-
# Configure pull to fetch-and-rebase rather than fetch-and-merge.
19-
# Also, prevent these rebases from inlining an existing local merge.
20-
# See this article for a thorough explanation:
21-
# https://medium.com/@porteneuve/getting-solid-at-git-rebase-vs-merge-4fa1a48c53aa#.ntv2atccl
22-
[pull]
23-
rebase = preserve
24-
2527
[rebase]
2628
autoStash = true
2729

@@ -41,8 +43,8 @@
4143
maxretries = 10
4244

4345
[filter "lfs"]
44-
clean = git-lfs clean %f
45-
smudge = git-lfs smudge %f
46+
clean = git-lfs clean -- %f
47+
smudge = git-lfs smudge -- %f
4648
process = git-lfs filter-process
4749
required = true
4850

@@ -75,6 +77,7 @@
7577
###############################################################################
7678
adsk = "!f() { \
7779
KIT_PATH=$(dirname \"$(git config include.path)\") && \
80+
ENV=$(git config adsk.environment || true) && \
7881
COMMAND=$1 && \
7982
if [ -n \"$COMMAND\" ]; then \
8083
shift 1; \
@@ -86,6 +89,8 @@
8689
rm \"$TMP_SETUP\"; \
8790
elif [ \"$COMMAND\" = \"install\" ]; then \
8891
echo \"Enterprise config already installed!\"; \
92+
elif [ -n \"$ENV\" ] && [ -e "$KIT_PATH/envs/$ENV/$COMMAND.sh" ]; then \
93+
bash \"$KIT_PATH/envs/$ENV/$COMMAND.sh\" \"$@\"; \
8994
elif [ -e \"$KIT_PATH/$COMMAND.sh\" ]; then \
9095
bash \"$KIT_PATH/$COMMAND.sh\" \"$@\"; \
9196
else \
@@ -99,3 +104,10 @@
99104
###############################################################################
100105
[ghfw]
101106
disableverification = true
107+
108+
###############################################################################
109+
# More helpful diff'ing of one line JSON files
110+
###############################################################################
111+
[diff "json"]
112+
textconv = "perl -MJSON::PP -e '$j = JSON::PP->new->pretty->canonical; print $j->encode($j->decode(<>))'"
113+
cachetextconv = true

copr.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env bash
2-
#
3-
# Checkout a Pull Request
4-
#
5-
# Usage: git <KIT_ID> copr <GitHub Pull Request number>
6-
#
7-
# c.f. https://gist.github.com/gnarf/5406589#gistcomment-1243876
8-
#
2+
#/
3+
#/ Checkout a Pull Request
4+
#/
5+
#/ Usage: git $KIT_ID copr <GitHub Pull Request number>
6+
#/
7+
#/ c.f. https://gist.github.com/gnarf/5406589#gistcomment-1243876
8+
#/
99
set -e
1010

1111
git fetch --force --update-head-ok ${2:-origin} refs/pull/$1/head:pr/$1

download-blob.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
#/
3+
#/ Download a Git object from GitHub via API.
4+
#/
5+
#/ Usage: git $KIT_ID download-blob [org/repo] [git-object-id]
6+
#/
7+
set -e
8+
9+
KIT_PATH=$(dirname "$0")
10+
. "$KIT_PATH/enterprise.constants"
11+
. "$KIT_PATH/lib/setup_helpers.sh"
12+
13+
[ $# -eq 2 ] || error_exit 'Please provide "org/repo" and "Git Object ID" as parameters.'
14+
15+
SLUG=$1
16+
OBJ_ID=$2
17+
18+
USER=$(git config --global adsk.github.account)
19+
[ -z "$USER" ] && error_exit 'Username must not be empty!'
20+
21+
TOKEN="$(get_credentials $GITHUB_SERVER $USER)"
22+
[ -z "$TOKEN" ] && error_exit "No credentials found. Run 'git adsk'!"
23+
24+
curl $CURL_RETRY_OPTIONS --silent --fail --user "$USER:$TOKEN" \
25+
-H "Accept: application/vnd.github.VERSION.raw" \
26+
https://$GITHUB_SERVER/api/v3/repos/$SLUG/git/blobs/$OBJ_ID

enable-public-push.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bash
2-
#
3-
# Override the Enterprise Config push protection feature configure in
4-
# config.include.
5-
#
6-
# Usage: git <KIT_ID> enable-public-push <server/org/repo>
7-
#
2+
#/
3+
#/ Override the Enterprise Config push protection feature configure in
4+
#/ config.include.
5+
#/
6+
#/ Usage: git $KIT_ID enable-public-push <server/org/repo>
7+
#/
88
set -e
99

1010
KIT_PATH=$(dirname "$0")

enterprise.constants

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,21 @@
22
# Configure these variables. See README.md for details.
33
###############################################################################
44

5-
# Define the name of the setup command for your company
6-
# Attention: This must match the alias defined in config.include!
7-
KIT_ID='adsk'
5+
KIT_ID='adsk' # This must match the alias defined in config.include
86

9-
# Define your GitHub Enterprise server
107
GITHUB_SERVER='git.yourcompany.com'
11-
12-
# Define the path of this repo on your GitHub Enterprise server
138
KIT_ORG_REPO='yourorg/enterprise-config-for-git'
14-
15-
# Register an OAuth application on your GitHub Enterprise server:
16-
# https://developer.github.com/v3/oauth/
9+
KIT_TESTFILE="https://$GITHUB_SERVER/api/v3"
10+
KIT_REMOTE_URL="https://$GITHUB_SERVER/$KIT_ORG_REPO.git"
1711
KIT_CLIENT_ID=<< YOUR OAUTH CLIENT ID >>
1812
KIT_CLIENT_SECRET=<< YOUR OAUTH SECRET >>
19-
20-
# Define the link to your source code policy
2113
KIT_SOURCE_CODE_POLICY_URL=https://yourcompany.com/policy
2214

23-
# Define a message for the users in case of errors
2415
ERROR_HELP_MESSAGE="Please contact [email protected]!"
2516

17+
# Versions
18+
INSTALL_UPGRADE_GIT_VERSION=2.14.1 # On update make sure to update strings in install-helper.ps1, too!
19+
MINIMUM_ADVISED_GIT_VERSION=2.13.5
20+
MINIMUM_REQUIRED_GIT_VERSION=2.3.2
2621

27-
###############################################################################
28-
# No changes beyond this point
29-
###############################################################################
30-
31-
KIT_TESTFILE="https://$GITHUB_SERVER/raw/$KIT_ORG_REPO/master/README.md"
32-
KIT_REMOTE_URL="https://$GITHUB_SERVER/$KIT_ORG_REPO.git"
22+
MINIMUM_GIT_LFS_VERSION=2.2.1 # On update make sure to update $GIT_LFS_SHA256 in lib/*/setup_helpers.sh, too!

0 commit comments

Comments
 (0)