Skip to content

Commit 764430f

Browse files
committed
Merge branch 'portable-release'
This adds support to build a portable Git for Windows via portable/release.sh <version> which places the generated PortableGit-<version>.7z.exe into your home directory. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 394c95e + 5430d4b commit 764430f

File tree

11 files changed

+269
-1
lines changed

11 files changed

+269
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
*.swp
22
/git-extra/pkg/
33
/git-extra/src/
4+
/portable/root/cmd/
5+
/portable/root/git-bash.bat
6+
/portable/root/git-cmd.bat

git-for-windows.svg

Lines changed: 1 addition & 0 deletions
Loading

git-for-windows.xcf

34.1 KB
Binary file not shown.

make-file-list.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ die () {
88
test $# -gt 0 ||
99
die "Usage: $0 <package-name>..."
1010

11-
pacman -Ql $(pactree -u "$@") | grep -v '/$' | sed 's/^[^ ]* //'
11+
pacman -Ql $(for arg
12+
do
13+
pactree -u "$arg"
14+
done |
15+
sort |
16+
uniq) |
17+
grep -v '/$' |
18+
sed 's/^[^ ]* //'

portable/git-bash.bat.in

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@REM Do not use "echo off" to not affect any child calls.
2+
@SETLOCAL
3+
4+
@REM Get the absolute path to the current directory, which is assumed to be the
5+
@REM Git installation root.
6+
@FOR /F "delims=" %%I IN ("%~dp0") DO @SET git_install_root=%%~fI
7+
8+
@SET MSYSTEM=MINGW@@BITNESS@@
9+
10+
@IF NOT EXIST %git_install_root%usr\bin\mintty.exe GOTO startsh
11+
@START "Git Bash" "%git_install_root%usr\bin\mintty" -i /usr/share/git/git-for-windows.ico /usr/bin/bash --login %*
12+
@EXIT
13+
14+
:startsh
15+
@START "Git Bash" "%git_install_root%usr\bin\bash" --login -i %*
16+
@EXIT

portable/git-cmd.bat.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@REM Do not use "echo off" to not affect any child calls.
2+
@SETLOCAL
3+
4+
@REM Get the absolute path to the current directory, which is assumed to be the
5+
@REM Git installation root.
6+
@FOR /F "delims=" %%I IN ("%~dp0") DO @SET git_install_root=%%~fI
7+
@SET PATH=%git_install_root%\usr\bin;%git_install_root%\mingw@@BITNESS@@\bin;%git_install_root%\cmd;%PATH%
8+
9+
@IF NOT EXIST "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
10+
@IF NOT EXIST "%HOME%" @set HOME=%USERPROFILE%
11+
12+
@SET PLINK_PROTOCOL=ssh
13+
@IF NOT DEFINED TERM SET TERM=msys
14+
15+
@SET MSYSTEM=MINGW@@BITNESS@@
16+
17+
@CD /d %HOME%
18+
@CALL %COMSPEC%

portable/release.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/sh
2+
3+
# Build the portable Git for Windows.
4+
5+
test -z "$1" && {
6+
echo "Usage: $0 <version> [optional components]"
7+
exit 1
8+
}
9+
10+
die () {
11+
echo "$*" >&1
12+
exit 1
13+
}
14+
15+
ARCH="$(uname -m)"
16+
case "$ARCH" in
17+
i686)
18+
BITNESS=32
19+
;;
20+
x86_64)
21+
BITNESS=64
22+
;;
23+
*)
24+
die "Unhandled architecture: $ARCH"
25+
;;
26+
esac
27+
VERSION=$1
28+
shift
29+
TARGET="$HOME"/PortableGit-"$VERSION".7z.exe
30+
OPTS7="-m0=lzma -mx=9 -md=64M"
31+
TMPPACK=/tmp.7z
32+
SHARE="$(cd "$(dirname "$0")" && pwd)"
33+
34+
case "$SHARE" in
35+
*" "*)
36+
die "This script cannot handle spaces in $SHARE"
37+
;;
38+
esac
39+
40+
41+
# Generate a couple of files dynamically
42+
43+
mkdir -p "$SHARE/root/tmp" ||
44+
die "Could not make tmp/ directory"
45+
46+
mkdir -p "$SHARE/root/cmd" &&
47+
cp /mingw$BITNESS/libexec/git-core/git-log.exe "$SHARE/root/cmd/git.exe" ||
48+
die "Could not copy Git wrapper"
49+
50+
sed "s/@@BITNESS@@/$BITNESS/g" \
51+
< "$SHARE/git-cmd.bat.in" > "$SHARE/root/git-cmd.bat" ||
52+
die "Could not generate git-cmd.bat"
53+
54+
sed "s/@@BITNESS@@/$BITNESS/g" \
55+
< "$SHARE/git-bash.bat.in" > "$SHARE/root/git-bash.bat" ||
56+
die "Could not generate git-bash.bat"
57+
58+
59+
# Make a list of files to include
60+
61+
pacman_list () {
62+
pacman -Ql $(for arg
63+
do
64+
pactree -u "$arg"
65+
done |
66+
sort |
67+
uniq) |
68+
grep -v '/$' |
69+
sed 's/^[^ ]* //'
70+
}
71+
72+
LIST="$(pacman_list mingw-w64-$ARCH-git git-extra ncurses mintty vim \
73+
sed awk less grep gnupg findutils coreutils \
74+
dos2unix which $@|
75+
grep -v -e '\.[acho]$' -e '/aclocal/' \
76+
-e '/man/' \
77+
-e '^/usr/include/' -e '^/mingw32/include/' \
78+
-e '^/usr/share/doc/' -e '^/mingw32/share/doc/' \
79+
-e '^/usr/share/info/' -e '^/mingw32/share/info/' |
80+
sed 's/^\///')"
81+
82+
LIST="$LIST etc/profile etc/bash.bash_logout etc/bash.bashrc etc/fstab"
83+
LIST="$LIST mingw$BITNESS/etc/gitconfig"
84+
85+
# 7-Zip will strip absolute paths completely... therefore, we can add another
86+
# root directory like this:
87+
88+
LIST="$LIST $SHARE/root/*"
89+
90+
91+
# Make the self-extracting package
92+
93+
type 7za ||
94+
pacman -S p7zip ||
95+
die "Could not install 7-Zip"
96+
97+
echo "Creating archive" &&
98+
(cd / && 7za a $OPTS7 $TMPPACK $LIST) &&
99+
(cat "$SHARE/../net-installer/7zSD.sfx" &&
100+
echo ';!@Install@!UTF-8!' &&
101+
echo 'Progress="yes"' &&
102+
echo 'Title="Portable Git for Windows"' &&
103+
echo 'BeginPrompt="This program installs a complete Git for Windows"' &&
104+
echo 'CancelPrompt="Do you want to cancel Git installation?"' &&
105+
echo 'ExtractDialogText="Please, wait..."' &&
106+
echo 'ExtractPathText="Where do you want to install Git for Windows?"' &&
107+
echo 'ExtractTitle="Extracting..."' &&
108+
echo 'GUIFlags="8+32+64+256+4096"' &&
109+
echo 'GUIMode="1"' &&
110+
echo 'InstallPath="%PROGRAMFILES%\\Git"' &&
111+
echo 'OverwriteMode="0"' &&
112+
echo ';!@InstallEnd@!7z' &&
113+
cat "$TMPPACK") > "$TARGET" &&
114+
echo "Success! You will find the new installer at \"$TARGET\"." &&
115+
echo "It is a self-extracting .7z archive (just append .exe to the filename)" &&
116+
rm $TMPPACK
117+

portable/root/Git Bash.vbs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Set fso = CreateObject("Scripting.FileSystemObject")
2+
Set shell = CreateObject("WScript.Shell")
3+
4+
Const TemporaryFolder = 2
5+
linkfile = fso.BuildPath(fso.GetSpecialFolder(TemporaryFolder), "Git Bash.lnk")
6+
gitdir = fso.GetParentFolderName(WScript.ScriptFullName)
7+
8+
' Dynamically create a shortcut with the current directory as the working directory.
9+
Set link = shell.CreateShortcut(linkfile)
10+
link.TargetPath = fso.BuildPath(gitdir, "usr\bin\sh.exe")
11+
link.Arguments = "--login -i"
12+
link.IconLocation = fso.BuildPath(gitdir, "usr\share\git\git.ico")
13+
If WScript.Arguments.Length > 0 Then link.WorkingDirectory = WScript.Arguments(0)
14+
link.Save
15+
16+
Set app = CreateObject("Shell.Application")
17+
app.ShellExecute linkfile
18+

portable/root/README.portable

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
README.portable
2+
=======================
3+
4+
This version of Git for Windows is portable, i.e. does not need to
5+
be installed. It will run from any directory you place it in, even
6+
from a USB thumbdrive. It will not write permanent entries into the
7+
Windows registry. It does not need administrator privileges to "install".
8+
9+
10+
Installation
11+
------------
12+
13+
This package is contained in a 7-zip archive with a file name of the form
14+
'PortableGit-<versionstring>.7z.exe'. It is a self-extracting archive:
15+
you can (double-)click it and it will ask for the desired target directory
16+
(which defaults to C:\Program Files\Git). You may change that as needed or
17+
desired. Your user account needs write access to the selected directory.
18+
(You can move that directory with all its contents to a different place or
19+
computer at any time should you later desire so).
20+
21+
22+
Functional differences to the non-portable Git for Windows
23+
----------------------------------------------------------
24+
25+
This version does not offer you the convenient right-click context menu
26+
entries "Git GUI Here" and "Git Bash Here", because these would require
27+
to add entries into the Windows registry.
28+
29+
30+
Warning
31+
-------
32+
33+
Since this portable package does not modify any Windows %path%
34+
variables, it is not possible to run the git.exe and gitk.exe files
35+
directly. Start the Git Bash or Git Cmd instead, or add the cmd/ folder
36+
to your %path%.
37+
38+
39+
How to start using PortableGit
40+
------------------------------
41+
42+
If you are comfortable with a Unix-like shell, just launch 'git-bash.bat'.
43+
44+
If not, just launch 'git-cmd.bat'.
45+
46+
Alternatively, you can execute these commands to modify the %path%
47+
variable temporarily:
48+
49+
set gitdir=c:\portablegit
50+
set path=%gitdir%\cmd;%path%
51+
52+
Adjust the 'gitdir' according to your setup. As long as you do not
53+
close the command window, you can now simply type "git" or "gitk" to
54+
really call "c:\portablegit\cmd\git.cmd" or "c:\portablegit\cmd\gitk.cmd".
55+
56+
57+
Quick start
58+
-----------
59+
60+
Start configuring git with your personal settings:
61+
git config --global user.name "Joe Sixpack"
62+
git config --global user.email joe.sixpack@g_mail.com
63+
64+
Start using git:
65+
git --help
66+
67+
68+
How to change %path% permanently
69+
--------------------------------
70+
71+
You may also want to make the modification to the %path% variable a
72+
permanent one. The %path% variable may be changed:
73+
74+
* either on a System level (for all users in the lower pane), if you are
75+
an Administrator
76+
* or for your own user account only (in the upper pane).
77+
78+
To change the %path% variable permanently:
79+
80+
* right-click "My Computer",
81+
* select "Properties",
82+
* open "Advanced",
83+
* click "Environment Variables",
84+
* highlight the "Path" variable,
85+
* click "Edit" (either in upper or in lower pane),
86+
* add your specific path to front of "Variable value" field, separated
87+
by a semicolon from the existing entry.
88+
93.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)