@matheusbsbs / matheus-bagliano / commits / d713e2d87a
Fork 0

Make --squash work with the 'add' command too.

Avery Pennarun committed May 30, 2009 at 04:11 UTC d713e2d87a5003da02d95a4ac5be28a1e9fdc3ce
2 files changed +44 -20
git-subtree.sh
+39 -18
@@ -23,7 +23,7 @@ b,branch= create a new branch from the split subtree
23 ignore-joins ignore prior --rejoin commits
24 onto= try connecting new tree to an existing one
25 rejoin merge the new branch back into HEAD
26 - options for 'merge' and 'pull'
26 + options for 'add', 'merge', and 'pull'
27 squash merge subtree changes as a single commit
28 "
29 eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)
@@ -169,11 +169,16 @@ try_remove_previous()
169
170 find_latest_squash()
171 {
172 - debug "Looking for latest squash..."
172 + debug "Looking for latest squash ($dir)..."
173 dir="$1"
174 + sq=
175 + main=
176 + sub=
177 git log --grep="^git-subtree-dir: $dir\$" \
178 --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
179 while read a b junk; do
180 + debug "$a $b $junk"
181 + debug "{{$sq/$main/$sub}}"
182 case "$a" in
183 START) sq="$b" ;;
184 git-subtree-mainline:) main="$b" ;;
@@ -202,6 +207,8 @@ find_existing_splits()
207 debug "Looking for prior splits..."
208 dir="$1"
209 revs="$2"
210 + main=
211 + sub=
212 git log --grep="^git-subtree-dir: $dir\$" \
213 --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs |
214 while read a b junk; do
@@ -284,21 +291,21 @@ squash_msg()
291 dir="$1"
292 oldsub="$2"
293 newsub="$3"
287 - oldsub_short=$(git rev-parse --short "$oldsub")
294 newsub_short=$(git rev-parse --short "$newsub")
289 - cat <<-EOF
290 - Squashed '$dir/' changes from $oldsub_short..$newsub_short
291 -
292 - EOF
295
294 - git log --pretty=tformat:'%h %s' "$oldsub..$newsub"
295 - git log --pretty=tformat:'REVERT: %h %s' "$newsub..$oldsub"
296 + if [ -n "$oldsub" ]; then
297 + oldsub_short=$(git rev-parse --short "$oldsub")
298 + echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"
299 + echo
300 + git log --pretty=tformat:'%h %s' "$oldsub..$newsub"
301 + git log --pretty=tformat:'REVERT: %h %s' "$newsub..$oldsub"
302 + else
303 + echo "Squashed '$dir/' content from commit $newsub_short"
304 + fi
305
297 - cat <<-EOF
298 -
299 - git-subtree-dir: $dir
300 - git-subtree-split: $newsub
301 - EOF
306 + echo
307 + echo "git-subtree-dir: $dir"
308 + echo "git-subtree-split: $newsub"
309 }
310
311 toptree_for_commit()
@@ -341,8 +348,13 @@ new_squash_commit()
348 oldsub="$2"
349 newsub="$3"
350 tree=$(toptree_for_commit $newsub) || exit $?
344 - squash_msg "$dir" "$oldsub" "$newsub" |
345 - git commit-tree "$tree" -p "$old" || exit $?
351 + if [ -n "$old" ]; then
352 + squash_msg "$dir" "$oldsub" "$newsub" |
353 + git commit-tree "$tree" -p "$old" || exit $?
354 + else
355 + squash_msg "$dir" "" "$newsub" |
356 + git commit-tree "$tree" || exit $?
357 + fi
358 }
359
360 copy_or_skip()
@@ -422,9 +434,18 @@ cmd_add()
434 else
435 headp=
436 fi
425 - commit=$(add_msg "$dir" "$headrev" "$rev" |
426 - git commit-tree $tree $headp -p "$rev") || exit $?
437 +
438 + if [ -n "$squash" ]; then
439 + rev=$(new_squash_commit "" "" "$rev") || exit $?
440 + commit=$(echo "Merge commit '$rev' as '$dir'" |
441 + git commit-tree $tree $headp -p "$rev") || exit $?
442 + else
443 + commit=$(add_msg "$dir" "$headrev" "$rev" |
444 + git commit-tree $tree $headp -p "$rev") || exit $?
445 + fi
446 git reset "$commit" || exit $?
447 +
448 + say "Added dir '$dir'"
449 }
450
451 cmd_split()
todo
+5 -2
@@ -10,11 +10,14 @@
10 "-s subtree" should be given an explicit subtree option?
11 There doesn't seem to be a way to do this. We'd have to
12 patch git-merge-subtree. Ugh.
13 + (but we could avoid this problem by generating squashes with
14 + exactly the right subtree structure, rather than using
15 + subtree merge...)
16
17 add a 'push' subcommand to parallel 'pull'
18
19 add a 'log' subcommand to see what's new in a subtree?
20
18 - add a --squash option so we don't merge histories but can still split
19 -
21 add to-submodule and from-submodule commands
22 +
23 + automated tests for --squash stuff