Skip to content

Commit 8262b94

Browse files
author
Lars Schneider
committed
Merge git adsk 1.2.2
1 parent f3fcfce commit 8262b94

18 files changed

+342
-113
lines changed

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
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.
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-L35)) 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-L39)) 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,12 +11,9 @@ 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 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).
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)
2017
* Configure your desired [company email pattern](./lib/setup_helpers.sh#L84).
2118
* Create a production branch based on the master branch.
2219

checkout.sh

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

clone.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@
33
# Clone Git repositories and download Git LFS files in parallel.
44
# See more info here: https://github.com/github/git-lfs/issues/931
55
#
6-
# Usage: git adsk clone <repository URL> [<target directory>]
6+
# Usage: git <KIT_ID> clone <repository URL> [<target directory>]
77
#
88
set -e
99

10-
git -c filter.lfs.smudge=cat clone --recursive $@
11-
if [[ -z $2 ]]; then
12-
CLONE_PATH=$(basename ${1%.git});
13-
else
14-
CLONE_PATH=$2;
15-
fi
16-
cd "$CLONE_PATH"
17-
git-lfs pull
10+
git-lfs clone --recursive $@

config.include

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@
4242
st=status
4343
br=branch
4444
lol = "log --pretty=oneline --abbrev-commit --graph --decorate"
45+
prlog = "log --pretty=oneline --abbrev-commit --graph --decorate --first-parent"
4546

4647

4748
###############################################################################
4849
# Enterprise Config setup command
4950
###############################################################################
5051
adsk = "!f() { \
51-
KIT_PATH=$(dirname $(git config include.path)) && \
52+
KIT_PATH=$(dirname \"$(git config include.path)\") && \
5253
COMMAND=$1 && \
5354
if [ -n \"$COMMAND\" ]; then \
5455
shift 1; \
@@ -58,6 +59,8 @@
5859
cp \"$KIT_PATH/setup.sh\" \"$TMP_SETUP\" && \
5960
bash \"$TMP_SETUP\" \"$KIT_PATH\" $@ && \
6061
rm \"$TMP_SETUP\"; \
62+
elif [ \"$COMMAND\" = \"install\" ]; then \
63+
echo \"Enterprise config already installed!\"; \
6164
elif [ -e \"$KIT_PATH/$COMMAND.sh\" ]; then \
6265
bash \"$KIT_PATH/$COMMAND.sh\" $@; \
6366
else \

enable-public-push.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
# Override the Enterprise Config push protection feature configure in
44
# config.include.
55
#
6-
# Usage: git adsk enable-public-push <server/org/repo>
6+
# Usage: git <KIT_ID> enable-public-push <server/org/repo>
77
#
88
set -e
99

10+
KIT_PATH=$(dirname "$0")
11+
. "$KIT_PATH/enterprise.constants"
12+
1013
REPO=$1
1114
git config --global url.https://$REPO.pushInsteadOf https://$REPO
1215
git config --global url.git@$REPO.pushInsteadOf git@$REPO
@@ -16,7 +19,6 @@ git config --global url.git@$REPO.pushInsteadOf git@$REPO
1619
### Enterprise Config
1720
###
1821
19-
Git push to public repo on "$REPO" enabled. Be careful and please respect the source code policy!
22+
Git push to public repo on "$REPO" enabled. Be careful and please respect the source code policy: $KIT_SOURCE_CODE_POLICY_URL
2023
2124
EOM
22-

enterprise.constants

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
###############################################################################
2+
# Configure these variables. See README.md for details.
3+
###############################################################################
4+
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'
8+
9+
# Define your GitHub Enterprise server
10+
GITHUB_SERVER='git.yourcompany.com'
11+
12+
# Define the path of this repo on your GitHub Enterprise server
13+
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/
17+
KIT_CLIENT_ID=<< YOUR OAUTH CLIENT ID >>
18+
KIT_CLIENT_SECRET=<< YOUR OAUTH SECRET >>
19+
20+
# Define the link to your source code policy
21+
KIT_SOURCE_CODE_POLICY_URL=https://yourcompany.com/policy
22+
23+
# Define a message for the users in case of errors
24+
ERROR_HELP_MESSAGE="Please contact [email protected]!"
25+
26+
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"

help.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,52 @@
22
#
33
set -e
44

5+
KIT_PATH=$(dirname "$0")
6+
. "$KIT_PATH/enterprise.constants"
7+
8+
# Infer a github url from a remote url
9+
INFO_URL=${KIT_REMOTE_URL%%.git}
10+
INFO_URL=${INFO_URL/#git@/https:\/\/}
11+
512
read -r -d '\0' HELP <<EOM
613
###
714
### Enterprise Config
815
###
916
1017
# Setup
1118
Description: Configures your machine to use Git.
12-
Command: git adsk
19+
Command: git $KIT_ID
1320
1421
# Teardown
1522
Description: Removes all Git credentials from your machine.
16-
Command: git adsk teardown
23+
Command: git $KIT_ID teardown
1724
1825
# Clone
1926
Description: Fast clone a repository with Git LFS files and submodules.
20-
Command: git adsk clone <repository URL> [<target directory>]
27+
Command: git $KIT_ID clone <repository URL> [<target directory>]
2128
2229
# Pull
2330
Description: Pull changes from a repository and all its submodules.
24-
Command: git adsk pull
31+
Command: git $KIT_ID pull
32+
33+
# Deleted
34+
Description: list the files that have been deleted from the current repository
35+
Command: git adsk show-deleted [-h] [<path/to/file>]
36+
Example: git adsk show-deleted
2537
2638
# Help
2739
Description: This help page.
28-
Command: git adsk help
40+
Command: git $KIT_ID help
2941
3042
# Version
3143
Description: Print version information.
32-
Command: git adsk version
44+
Command: git $KIT_ID version
3345
46+
---
47+
You can easily add your own commands. See $INFO_URL for details.
48+
49+
If you run into any trouble:
50+
$ERROR_HELP_MESSAGE
3451
\0
3552
EOM
3653
echo "$HELP"
37-

lib/lnx/find_pfx.pl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env perl
2+
3+
# We don't want the plumbing directory.
4+
# We would like to see what the user would when
5+
# typing `which git`
6+
7+
use 5.016;
8+
use warnings;
9+
use File::Basename;
10+
11+
for my $dir ( split( /:/, $ENV{'PATH'} ) ) {
12+
next if ( $dir =~ /git-core/ );
13+
if ( -f "$dir/git" ) {
14+
print "$dir\n";
15+
exit(0);
16+
}
17+
}
18+
die "git not found in " . $ENV{'PATH'} . "\n";

lib/lnx/setup_helpers.sh

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function credential_helper_parameters {
1010
function install_git_lfs {
1111
local KIT_PATH=$1
1212
local VERSION=$2
13-
local GIT_LFS_CHECKSUM="578a3b9c44edcadc7e9e32a576910d6f"
13+
local GIT_LFS_CHECKSUM="aba77a55638502b4d58cad5c52bfdf98"
1414
# Run this to calculate the hash for a new version:
1515
# export V="1.1.1"; curl --location https://github.com/github/git-lfs/releases/download/v$V/git-lfs-linux-amd64-$V.tar.gz | md5
1616

@@ -25,21 +25,18 @@ function install_git_lfs {
2525
error_exit "Failed to extract the contents of Git-LFS archive ($SRC_URL)"
2626
fi
2727

28+
chmod -R 775 $EXTRACT_FOLDER
2829
for f in $(ls "$EXTRACT_FOLDER/"); do
29-
if [[ -x "$EXTRACT_FOLDER/$f/install.sh" ]]; then
30-
local PFX=$(dirname $(dirname $(which git)))
31-
if ( has_command git-lfs ); then
32-
# reuse existing install folder if this is an update
33-
PFX=$(dirname $(dirname $(which git-lfs)))
34-
fi
35-
echo "Installing git-lfs to $PFX, please supply credentials if prompted."
36-
if ! (cd "$EXTRACT_FOLDER/$f"; sudo PREFIX=$PFX "$EXTRACT_FOLDER/$f/install.sh"); then
37-
rm -f "$DOWNLOAD_FILE"
38-
rm -rf "$EXTRACT_FOLDER"
39-
error_exit "Failed to execute the Git-LFS installation script"
40-
fi
41-
break
30+
local PFX="/usr/bin"
31+
if ( has_command git-lfs ); then
32+
# reuse existing install folder if this is an update
33+
PFX=$(dirname $(which git-lfs))
34+
else
35+
PFX=$(perl "$KIT_PATH/lib/lnx/find_pfx.pl")
4236
fi
37+
chmod 755 "$EXTRACT_FOLDER/$f/git-lfs"
38+
sudo cp "$EXTRACT_FOLDER/$f/git-lfs" $PFX
39+
sudo chmod 755 $PFX/git-lfs
4340
done
4441

4542
if [[ -e $DOWNLOAD_FILE ]]; then

lib/osx/setup_helpers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function _macports_has_port() {
1414

1515
function _managerless_lfs_install() {
1616
local VERSION=$1
17-
local GIT_LFS_CHECKSUM=2e43480adbd3694b756c95558ecdf5cf
17+
local GIT_LFS_CHECKSUM=06d82272deabbc0bf9642868170fa7dd
1818
# Run this to calculate the hash for a new version:
1919
# export V="1.1.1"; curl --location https://github.com/github/git-lfs/releases/download/v$V/git-lfs-darwin-amd64-$V.tar.gz | md5
2020

@@ -45,7 +45,7 @@ function _managerless_lfs_install() {
4545
PFX=/usr/local
4646
fi
4747
echo "Installing git-lfs to $PFX, please supply credentials if prompted."
48-
if ! (cd "$EXTRACT_FOLDER/$f"; sudo PREFIX=$PFX "$EXTRACT_FOLDER/$f/install.sh"); then
48+
if ! (cd "$EXTRACT_FOLDER/$f"; sudo env PREFIX=$PFX "$EXTRACT_FOLDER/$f/install.sh"); then
4949
rm -f "$DOWNLOAD_FILE"
5050
rm -rf "$EXTRACT_FOLDER"
5151
error_exit "Failed to execute the Git-LFS installation script"

0 commit comments

Comments
 (0)