diff options
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | git-checkout-script | 3 | ||||
-rwxr-xr-x | git-commit-script | 10 | ||||
-rwxr-xr-x | git-fetch-script | 4 | ||||
-rwxr-xr-x | git-prune-script | 6 | ||||
-rwxr-xr-x | git-pull-script | 5 | ||||
-rw-r--r-- | git-repack-script | 7 | ||||
-rwxr-xr-x | git-reset-script | 2 | ||||
-rwxr-xr-x | git-resolve-script | 14 | ||||
-rw-r--r-- | git-sh-setup-script | 17 |
10 files changed, 40 insertions, 30 deletions
@@ -34,7 +34,7 @@ SCRIPTS=git git-apply-patch-script git-merge-one-file-script git-prune-script \ 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 ea7fef54ab..bf52e3bb24 100755 --- a/git-checkout-script +++ b/git-checkout-script @@ -1,5 +1,6 @@ #!/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 2632afdeed..c6f8ee2b3d 100755 --- a/git-commit-script +++ b/git-commit-script @@ -3,16 +3,12 @@ # 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 8a2d37d623..acb1e56e70 100755 --- a/git-fetch-script +++ b/git-fetch-script @@ -9,8 +9,8 @@ if [ "$2" = "tag" ]; then 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 ec9f72de79..97646685b7 100755 --- a/git-prune-script +++ b/git-prune-script @@ -1,4 +1,7 @@ #!/bin/sh + +. git-sh-setup-script || die "Not a git archive" + dryrun= while case "$#" in 0) break ;; esac do @@ -11,9 +14,6 @@ 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 961edc481b..0ef6be3547 100755 --- a/git-pull-script +++ b/git-pull-script @@ -1,5 +1,7 @@ #!/bin/sh # +. git-sh-setup-script || die "Not a git archive" + merge_repo=$1 merge_name=$(echo "$1" | sed 's:\.git/*$::') @@ -15,9 +17,6 @@ then 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 92281c27fd..15b7fd6a15 100644 --- a/git-repack-script +++ b/git-repack-script @@ -1,6 +1,6 @@ #!/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) || @@ -9,5 +9,6 @@ if [ -z "$packname" ]; then 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 fe773388c9..0c02aa6423 100755 --- a/git-reset-script +++ b/git-reset-script @@ -1,5 +1,5 @@ #!/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 bf2fb2d431..03c15a98b0 100755 --- a/git-resolve-script +++ b/git-resolve-script @@ -4,13 +4,12 @@ # # 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 @@ -21,8 +20,7 @@ dropheads() { # 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 @@ -31,8 +29,7 @@ echo $merge > "$GIT_DIR"/LAST_MERGE 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 @@ -57,8 +54,7 @@ if [ $? -ne 0 ]; 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 new file mode 100644 index 0000000000..660c524ce8 --- /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" ] |