summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/git-commit.txt3
-rw-r--r--cache.h1
-rwxr-xr-xgit-checkout.sh6
-rwxr-xr-xgit-commit.sh22
-rwxr-xr-xgit-fetch.sh6
-rwxr-xr-xgit-merge.sh44
-rwxr-xr-xgit-pull.sh4
-rwxr-xr-xgit-rebase.sh3
-rwxr-xr-xgit-reset.sh6
-rwxr-xr-xgit-revert.sh3
-rwxr-xr-xgit-sh-setup.sh11
-rw-r--r--sha1_file.c6
-rw-r--r--t/lib-git-svn.sh2
-rw-r--r--write_or_die.c12
-rw-r--r--wt-status.c2
15 files changed, 65 insertions, 66 deletions
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index cb081cda89..b4528d72ba 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -32,7 +32,8 @@ methods:
4. by using the -a switch with the 'commit' command to automatically "add"
changes from all known files i.e. files that have already been committed
- before, and perform the actual commit.
+ before, and to automatically "rm" files that have been
+ removed from the working tree, and perform the actual commit.
The gitlink:git-status[1] command can be used to obtain a
summary of what is included by any of the above for the next
diff --git a/cache.h b/cache.h
index c482c32a03..620b6a4ed4 100644
--- a/cache.h
+++ b/cache.h
@@ -434,7 +434,6 @@ extern char *git_log_output_encoding;
extern int copy_fd(int ifd, int ofd);
extern int read_in_full(int fd, void *buf, size_t count);
-extern void read_or_die(int fd, void *buf, size_t count);
extern int write_in_full(int fd, const void *buf, size_t count);
extern void write_or_die(int fd, const void *buf, size_t count);
extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
diff --git a/git-checkout.sh b/git-checkout.sh
index a2b8e4fa4a..66e40b90eb 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -135,11 +135,7 @@ fi
# We are switching branches and checking out trees, so
# we *NEED* to be at the toplevel.
-cdup=$(git-rev-parse --show-cdup)
-if test ! -z "$cdup"
-then
- cd "$cdup"
-fi
+cd_to_toplevel
[ -z "$new" ] && new=$old && new_name="$old_name"
diff --git a/git-commit.sh b/git-commit.sh
index b6387239dd..e23918cd6c 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -316,22 +316,16 @@ esac
################################################################
# Prepare index to have a tree to be committed
-TOP=`git-rev-parse --show-cdup`
-if test -z "$TOP"
-then
- TOP=./
-fi
-
case "$all,$also" in
t,)
save_index &&
(
- cd "$TOP"
- GIT_INDEX_FILE="$NEXT_INDEX"
- export GIT_INDEX_FILE
+ cd_to_toplevel &&
+ GIT_INDEX_FILE="$NEXT_INDEX" &&
+ export GIT_INDEX_FILE &&
git-diff-files --name-only -z |
git-update-index --remove -z --stdin
- )
+ ) || exit
;;
,t)
save_index &&
@@ -339,11 +333,11 @@ t,)
git-diff-files --name-only -z -- "$@" |
(
- cd "$TOP"
- GIT_INDEX_FILE="$NEXT_INDEX"
- export GIT_INDEX_FILE
+ cd_to_toplevel &&
+ GIT_INDEX_FILE="$NEXT_INDEX" &&
+ export GIT_INDEX_FILE &&
git-update-index --remove -z --stdin
- )
+ ) || exit
;;
,)
case "$#" in
diff --git a/git-fetch.sh b/git-fetch.sh
index c58704d794..87b940b85b 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -5,12 +5,8 @@ USAGE='<fetch-options> <repository> <refspec>...'
SUBDIRECTORY_OK=Yes
. git-sh-setup
set_reflog_action "fetch $*"
+cd_to_toplevel ;# probably unnecessary...
-TOP=$(git-rev-parse --show-cdup)
-if test ! -z "$TOP"
-then
- cd "$TOP"
-fi
. git-parse-remote
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
diff --git a/git-merge.sh b/git-merge.sh
index 3eef048efc..7b590268ed 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -5,12 +5,14 @@
USAGE='[-n] [--no-commit] [--squash] [-s <strategy>] [-m=<merge-message>] <commit>+'
+SUBDIRECTORY_OK=Yes
. git-sh-setup
set_reflog_action "merge $*"
require_work_tree
+cd_to_toplevel
test -z "$(git ls-files -u)" ||
- die "You are in a middle of conflicted merge."
+ die "You are in the middle of a conflicted merge."
LF='
'
@@ -299,24 +301,30 @@ f,*)
;;
?,1,*,)
# We are not doing octopus, not fast forward, and have only
- # one common. See if it is really trivial.
- git var GIT_COMMITTER_IDENT >/dev/null || exit
-
- echo "Trying really trivial in-index merge..."
+ # one common.
git-update-index --refresh 2>/dev/null
- if git-read-tree --trivial -m -u -v $common $head "$1" &&
- result_tree=$(git-write-tree)
- then
- echo "Wonderful."
- result_commit=$(
- echo "$merge_msg" |
- git-commit-tree $result_tree -p HEAD -p "$1"
- ) || exit
- finish "$result_commit" "In-index merge"
- dropsave
- exit 0
- fi
- echo "Nope."
+ case " $use_strategies " in
+ *' recursive '*|*' recur '*)
+ : run merge later
+ ;;
+ *)
+ # See if it is really trivial.
+ git var GIT_COMMITTER_IDENT >/dev/null || exit
+ echo "Trying really trivial in-index merge..."
+ if git-read-tree --trivial -m -u -v $common $head "$1" &&
+ result_tree=$(git-write-tree)
+ then
+ echo "Wonderful."
+ result_commit=$(
+ echo "$merge_msg" |
+ git-commit-tree $result_tree -p HEAD -p "$1"
+ ) || exit
+ finish "$result_commit" "In-index merge"
+ dropsave
+ exit 0
+ fi
+ echo "Nope."
+ esac
;;
*)
# An octopus. If we can reach all the remote we are up to date.
diff --git a/git-pull.sh b/git-pull.sh
index e9826fc4ce..959261757c 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -6,12 +6,14 @@
USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <repo> <head>...'
LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
+SUBDIRECTORY_OK=Yes
. git-sh-setup
set_reflog_action "pull $*"
require_work_tree
+cd_to_toplevel
test -z "$(git ls-files -u)" ||
- die "You are in a middle of conflicted merge."
+ die "You are in the middle of a conflicted merge."
strategy_args= no_summary= no_commit= squash=
while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
diff --git a/git-rebase.sh b/git-rebase.sh
index 98f9558145..c8bd0f99d1 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -27,9 +27,12 @@ Example: git-rebase master~1 topic
/ --> /
D---E---F---G master D---E---F---G master
'
+
+SUBDIRECTORY_OK=Yes
. git-sh-setup
set_reflog_action rebase
require_work_tree
+cd_to_toplevel
RESOLVEMSG="
When you have resolved this problem run \"git rebase --continue\".
diff --git a/git-reset.sh b/git-reset.sh
index b9045bc762..91c7e6e664 100755
--- a/git-reset.sh
+++ b/git-reset.sh
@@ -53,11 +53,7 @@ then
exit
fi
-TOP=$(git-rev-parse --show-cdup)
-if test ! -z "$TOP"
-then
- cd "$TOP"
-fi
+cd_to_toplevel
if test "$reset_type" = "--hard"
then
diff --git a/git-revert.sh b/git-revert.sh
index fcbefb4e68..71cbcbc2b8 100755
--- a/git-revert.sh
+++ b/git-revert.sh
@@ -19,8 +19,11 @@ case "$0" in
echo >&2 "What are you talking about?"
exit 1 ;;
esac
+
+SUBDIRECTORY_OK=Yes ;# we will cd up
. git-sh-setup
require_work_tree
+cd_to_toplevel
no_commit=
while case "$#" in 0) break ;; esac
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 57f7f77776..6b1c1423eb 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -36,6 +36,17 @@ is_bare_repository () {
esac
}
+cd_to_toplevel () {
+ cdup=$(git-rev-parse --show-cdup)
+ if test ! -z "$cdup"
+ then
+ cd "$cdup" || {
+ echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
+ exit 1
+ }
+ fi
+}
+
require_work_tree () {
test $(is_bare_repository) = false ||
die "fatal: $0 cannot be used without a working tree."
diff --git a/sha1_file.c b/sha1_file.c
index 2a5be53fac..1b1c0f7b4d 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -572,7 +572,8 @@ static void open_packed_git(struct packed_git *p)
die("cannot set FD_CLOEXEC");
/* Verify we recognize this pack file format. */
- read_or_die(p->pack_fd, &hdr, sizeof(hdr));
+ if (read_in_full(p->pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr))
+ die("file %s is far too short to be a packfile", p->pack_name);
if (hdr.hdr_signature != htonl(PACK_SIGNATURE))
die("file %s is not a GIT packfile", p->pack_name);
if (!pack_version_ok(hdr.hdr_version))
@@ -588,7 +589,8 @@ static void open_packed_git(struct packed_git *p)
num_packed_objects(p));
if (lseek(p->pack_fd, p->pack_size - sizeof(sha1), SEEK_SET) == -1)
die("end of packfile %s is unavailable", p->pack_name);
- read_or_die(p->pack_fd, sha1, sizeof(sha1));
+ if (read_in_full(p->pack_fd, sha1, sizeof(sha1)) != sizeof(sha1))
+ die("packfile %s signature is unavailable", p->pack_name);
idx_sha1 = ((unsigned char *)p->index_base) + p->index_size - 40;
if (hashcmp(sha1, idx_sha1))
die("packfile %s does not match index", p->pack_name);
diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh
index a0f2814083..bb1d7b84bc 100644
--- a/t/lib-git-svn.sh
+++ b/t/lib-git-svn.sh
@@ -26,7 +26,7 @@ use SVN::Core;
use SVN::Repos;
\$SVN::Core::VERSION gt '1.1.0' or exit(42);
system(qw/svnadmin create --fs-type fsfs/, '$svnrepo') == 0 or exit(41);
-"
+" >&3 2>&4
x=$?
if test $x -ne 0
then
diff --git a/write_or_die.c b/write_or_die.c
index 4e8183e93e..046e79d485 100644
--- a/write_or_die.c
+++ b/write_or_die.c
@@ -17,18 +17,6 @@ int read_in_full(int fd, void *buf, size_t count)
return total;
}
-void read_or_die(int fd, void *buf, size_t count)
-{
- ssize_t loaded;
-
- loaded = read_in_full(fd, buf, count);
- if (loaded != count) {
- if (loaded < 0)
- die("read error (%s)", strerror(errno));
- die("read error: end of file");
- }
-}
-
int write_in_full(int fd, const void *buf, size_t count)
{
const char *p = buf;
diff --git a/wt-status.c b/wt-status.c
index daba9a6105..b7250e4310 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -335,7 +335,7 @@ void wt_status_print(struct wt_status *s)
if (s->amend)
printf("# No changes\n");
else if (s->workdir_dirty)
- printf("no changes added to commit (use \"git add\" and/or \"git commit [-a|-i|-o]\")\n");
+ printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n");
else if (s->workdir_untracked)
printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
else if (s->is_initial)