Do show the top-level working dir.
[git-shortcuts.git] / git-mread-and-commit
blobf86165de92db96ea9f63607663a19e94a5127883
1 #!/bin/bash
3 set -e
5 # How to refer to the new commit:
6 readonly TAG="$1"
7 shift
9 parent_opts=()
10 # We don't want to commit with current time, we want to commit with a time that is a function of the RCS content (actually, max), because this makes this command idempotent.
11 time=0
13 single-read() {
14 git read-tree -v "$@" "$parent"
15 parent_opts+=(-p "$parent")
16 # Keep the max time for the future commit:
17 local newtime="$(git show "$parent" --pretty=format:'%ct' | head -1)"
18 if (( newtime > time )); then time="$newtime"; fi
21 # First time, we should save the old index and start reading new stuff into it:
22 printf $"%s is saving your current index.\n" "$0"
23 readonly SAVED_INDEX="$(git write-tree)"
24 restore_index() {
25 printf $"%s is restoring your old index.\n" "$0"
26 git read-tree -v "$SAVED_INDEX"
28 trap restore_index EXIT # Yes, it will be executed when exiting after an error as well (checked).
30 parent="$1"
31 single-read
32 shift
34 for parent in "$@"; do
35 # Make it think there are no deletions (pass an empty tree as the source):
36 single-read -m -i "$(git the-empty-tree)"
37 shift
38 done
40 # The commit message is read from stdin.
41 GIT_COMMITTER_DATE="$time" \
42 GIT_AUTHOR_DATE="$time" \
43 git commit-tree "$(git write-tree)" "${parent_opts[@]}" \
44 | xargs git tag "$TAG"