summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: acb46f8)
raw | patch | inline | side by side (parent: acb46f8)
author | Linus Torvalds <torvalds@g5.osdl.org> | |
Fri, 8 Jul 2005 17:57:21 +0000 (10:57 -0700) | ||
committer | Linus Torvalds <torvalds@g5.osdl.org> | |
Fri, 8 Jul 2005 17:57:21 +0000 (10:57 -0700) |
It sets up the normal git environment variables and a few helper
functions (currently just "die()"), and returns ok if it all looks like
a git archive. So use it something like
. git-sh-setup-script || die "Not a git archive"
to make the rest of the git scripts more careful and readable.
functions (currently just "die()"), and returns ok if it all looks like
a git archive. So use it something like
. git-sh-setup-script || die "Not a git archive"
to make the rest of the git scripts more careful and readable.
Makefile | patch | blob | history | |
git-checkout-script | patch | blob | history | |
git-commit-script | patch | blob | history | |
git-fetch-script | patch | blob | history | |
git-prune-script | patch | blob | history | |
git-pull-script | patch | blob | history | |
git-repack-script | patch | blob | history | |
git-reset-script | patch | blob | history | |
git-resolve-script | patch | blob | history | |
git-sh-setup-script | [new file with mode: 0644] | patch | blob |
diff --git a/Makefile b/Makefile
index 82f63cdae828072890c47e836ddf7e6ca52ee231..d613a8c1315e7c05f6e54e22e955ff906c45b987 100644 (file)
--- a/Makefile
+++ b/Makefile
git-log-script git-shortlog git-cvsimport-script git-diff-script \
git-reset-script git-add-script git-checkout-script git-clone-script \
gitk git-cherry git-rebase-script git-relink-script git-repack-script \
- git-format-patch-script
+ git-format-patch-script git-sh-setup-script
PROG= git-update-cache git-diff-files git-init-db git-write-tree \
git-read-tree git-commit-tree git-cat-file git-fsck-cache \
diff --git a/git-checkout-script b/git-checkout-script
index ea7fef54ab6e1a6e04b87aa749c19ae916190d26..bf52e3bb24d3e679e396910c53924075e2f3a32b 100755 (executable)
--- a/git-checkout-script
+++ b/git-checkout-script
#!/bin/sh
-: ${GIT_DIR=.git}
+. git-sh-setup-script || die "Not a git archive"
+
old=$(git-rev-parse HEAD)
new=
force=
diff --git a/git-commit-script b/git-commit-script
index 2632afdeede1af08e59fe1163cc8be2ba9e9f5cf..c6f8ee2b3df1a93bcf9b167b5fc5d3ee30381fd8 100755 (executable)
--- a/git-commit-script
+++ b/git-commit-script
# Copyright (c) 2005 Linus Torvalds
#
+. git-sh-setup-script || die "Not a git archive"
+
usage () {
- echo 'git commit [-m existing-commit] [<path>...]'
- exit 1
+ die 'git commit [-m existing-commit] [<path>...]'
}
-: ${GIT_DIR=.git}
-if [ ! -d "$GIT_DIR" ]; then
- echo Not a git directory 1>&2
- exit 1
-fi
while case "$#" in 0) break ;; esac
do
case "$1" in
diff --git a/git-fetch-script b/git-fetch-script
index 8a2d37d623a71b71b0f1e86184c0bc88a25068df..acb1e56e70a974d276eb915a51fc5351801b24a5 100755 (executable)
--- a/git-fetch-script
+++ b/git-fetch-script
destination="$merge_name"
fi
-: ${GIT_DIR=.git}
-: ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
+. git-sh-setup-script || die "Not a git archive"
+
TMP_HEAD="$GIT_DIR/TMP_HEAD"
case "$merge_repo" in
diff --git a/git-prune-script b/git-prune-script
index ec9f72de793f88a82ea7b9780c76c4f665264d02..97646685b70ac18210be130566b2c36395120385 100755 (executable)
--- a/git-prune-script
+++ b/git-prune-script
#!/bin/sh
+
+. git-sh-setup-script || die "Not a git archive"
+
dryrun=
while case "$#" in 0) break ;; esac
do
shift;
done
-: ${GIT_DIR=.git}
-: ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
-
git-fsck-cache --cache --unreachable "$@" |
sed -ne '/unreachable /{
s/unreachable [^ ][^ ]* //
diff --git a/git-pull-script b/git-pull-script
index 961edc481b96b0081c816520bc0c4e2cfe5a43f8..0ef6be3547fe75b1758120161e1e3318b56ee6f4 100755 (executable)
--- a/git-pull-script
+++ b/git-pull-script
#!/bin/sh
#
+. git-sh-setup-script || die "Not a git archive"
+
merge_repo=$1
merge_name=$(echo "$1" | sed 's:\.git/*$::')
merge_head="refs/${type}s/$2"
fi
-: ${GIT_DIR=.git}
-: ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
-
git-fetch-script "$merge_repo" "$merge_head" || exit 1
git-resolve-script \
diff --git a/git-repack-script b/git-repack-script
index 92281c27fdda5f3b3dd0b0dfc01a4cb3182a686a..15b7fd6a15de3a3a5df6a7408f65410c37c0589e 100644 (file)
--- a/git-repack-script
+++ b/git-repack-script
#!/bin/sh
-: ${GIT_DIR=.git}
-: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
+. git-sh-setup-script || die "Not a git archive"
+
rm -f .tmp-pack-*
packname=$(git-rev-list --unpacked --objects $(git-rev-parse --all) |
git-pack-objects --non-empty --incremental .tmp-pack) ||
echo Nothing new to pack
exit 0
fi
-mv .tmp-pack-$packname.pack "$GIT_OBJECT_DIRECTORY/pack/pack-$packname.pack"
+mkdir -p "$GIT_OBJECT_DIRECTORY/pack" &&
+mv .tmp-pack-$packname.pack "$GIT_OBJECT_DIRECTORY/pack/pack-$packname.pack" &&
mv .tmp-pack-$packname.idx "$GIT_OBJECT_DIRECTORY/pack/pack-$packname.idx"
diff --git a/git-reset-script b/git-reset-script
index fe773388c9d55fdb87967bc04765fa94a83bf2c7..0c02aa6423ec485e19bd7439c926addbb8fd029d 100755 (executable)
--- a/git-reset-script
+++ b/git-reset-script
#!/bin/sh
-: ${GIT_DIR=.git}
+. git-sh-setup-script || die "Not a git archive"
git-read-tree --reset HEAD
git-update-cache --refresh
rm -f "$GIT_DIR/MERGE_HEAD"
diff --git a/git-resolve-script b/git-resolve-script
index bf2fb2d431da4702cd2b5fe3f414ce22c7ab284d..03c15a98b0527375d34f3369ab1cadb2f6bfc82c 100755 (executable)
--- a/git-resolve-script
+++ b/git-resolve-script
#
# Resolve two trees.
#
+. git-sh-setup-script || die "Not a git archive"
+
head=$(git-rev-parse --revs-only "$1")
merge=$(git-rev-parse --revs-only "$2")
merge_repo="$3"
-: ${GIT_DIR=.git}
-: ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
-
dropheads() {
rm -f -- "$GIT_DIR/MERGE_HEAD" \
"$GIT_DIR/LAST_MERGE" || exit 1
# but we do want it.
#
if [ -z "$head" -o -z "$merge" -o -z "$merge_repo" ]; then
- echo "git-resolve-script <head> <remote> <merge-repo-name>"
- exit 1
+ die "git-resolve-script <head> <remote> <merge-repo-name>"
fi
dropheads
common=$(git-merge-base $head $merge)
if [ -z "$common" ]; then
- echo "Unable to find common commit between" $merge $head
- exit 1
+ die "Unable to find common commit between" $merge $head
fi
if [ "$common" == "$merge" ]; then
git-merge-cache -o git-merge-one-file-script -a
if [ $? -ne 0 ]; then
echo $merge > "$GIT_DIR"/MERGE_HEAD
- echo "Automatic merge failed, fix up by hand"
- exit 1
+ die "Automatic merge failed, fix up by hand"
fi
result_tree=$(git-write-tree) || exit 1
fi
diff --git a/git-sh-setup-script b/git-sh-setup-script
--- /dev/null
+++ b/git-sh-setup-script
@@ -0,0 +1,17 @@
+#!/bin/sh
+#
+# Set up GIT_DIR and GIT_OBJECT_DIRECTORY
+# and return true if everything looks ok
+#
+: ${GIT_DIR=.git}
+: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
+
+die() {
+ echo "$@" >&2
+ exit 1
+}
+
+[ -d "$GIT_DIR" ] &&
+[ -d "$GIT_DIR/refs" ]
+[ -d "$GIT_OBJECT_DIRECTORY" ] &&
+[ -d "$GIT_OBJECT_DIRECTORY/00" ]