22set -e
33
44index_file=$( mktemp)
5-
65internal_error=true
7- trap ' rm -f $index_file; $internal_error && err "INTERNAL ERROR. FAILED!"' 0
6+ trap ' rm -f $index_file; $internal_error && err 255 "INTERNAL ERROR. FAILED!"' 0
87
9- usage=" Usage: git commit-filetree <branch> <path>"
10- [ -z " $2 " ] && {
11- echo 1>&2 " $usage "
8+ err () {
9+ local exitcode=" $1 " ; shift
1210 internal_error=false
13- exit 129
11+ echo 1>&2 " $@ "
12+ exit $exitcode
1413}
15- branch=refs/heads/$( echo $1 | sed -e ' s,^refs/heads/,,' )
1614
17- err () { internal_error=false ; echo 1>&2 " $@ " ; exit 1 ; }
15+ [ -z " $2 " ] && err 129 " Usage: git commit-filetree <branch> <path> "
1816
1917# Check that we have no uncommited or unknown files.
2018git diff-index --quiet HEAD \
21- || err " Cannot commit with uncommited files in working copy."
19+ || err 1 " Cannot commit with uncommited files in working copy."
2220[ -z " $( git ls-files --exclude-standard --others) " ] \
23- || err " Cannot commit with untracked files in working copy."
21+ || err 1 " Cannot commit with untracked files in working copy."
2422
25- git show-ref -q --verify $branch || {
26- internal_error=false
27- echo 1>&2 " Invalid ref: $branch "
28- exit 128
29- }
23+ branch=refs/heads/$( echo $1 | sed -e ' s,^refs/heads/,,' )
24+ git show-ref -q --verify $branch || err 128 " Invalid ref: $branch "
3025
3126source_sha=$( git show --quiet --pretty=' format:%h' )
3227
28+ # Switch to an index separate from repo working copy.
3329export GIT_INDEX_FILE=$index_file
30+
3431git read-tree --empty
3532git --work-tree=$2 add -A
3633tree_sha=$( git write-tree)
@@ -40,8 +37,6 @@ parent_tree_sha=$(git log -1 $branch --format='%T')
4037commit_msg=" Build from source commit $source_sha ."
4138commit_sha=$( echo " $commit_msg " | git commit-tree $tree_sha -p $branch )
4239
43-
44-
4540# XXX use -m below to update the log file as well
4641# (See /usr/share/doc/git/contrib/examples/git-commit.sh for an example.)
4742git update-ref $branch $commit_sha
0 commit comments