Skip to content

Commit e439979

Browse files
committed
Merge branch 'tv/rebase-stat'
* tv/rebase-stat: git-pull: Allow --stat and --no-stat to be used with --rebase git-rebase: Add --stat and --no-stat for producing diffstat on rebase
2 parents 8a396c0 + a334e12 commit e439979

File tree

5 files changed

+65
-14
lines changed

5 files changed

+65
-14
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,10 @@ pull.octopus::
11701170
pull.twohead::
11711171
The default merge strategy to use when pulling a single branch.
11721172

1173+
rebase.stat::
1174+
Whether to show a diffstat of what changed upstream since the last
1175+
rebase. False by default.
1176+
11731177
receive.fsckObjects::
11741178
If it is set to true, git-receive-pack will check all received
11751179
objects. It will abort in the case of a malformed object or a

Documentation/git-rebase.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ Alternatively, you can undo the 'git-rebase' with
192192

193193
git rebase --abort
194194

195+
CONFIGURATION
196+
-------------
197+
198+
rebase.stat::
199+
Whether to show a diffstat of what changed upstream since the last
200+
rebase. False by default.
201+
195202
OPTIONS
196203
-------
197204
<newbase>::
@@ -232,7 +239,15 @@ OPTIONS
232239

233240
-v::
234241
--verbose::
235-
Display a diffstat of what changed upstream since the last rebase.
242+
Be verbose. Implies --stat.
243+
244+
--stat::
245+
Show a diffstat of what changed upstream since the last rebase. The
246+
diffstat is also controlled by the configuration option rebase.stat.
247+
248+
-n::
249+
--no-stat::
250+
Do not show a diffstat as part of the rebase process.
236251

237252
--no-verify::
238253
This option bypasses the pre-rebase hook. See also linkgit:githooks[5].

git-pull.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cd_to_toplevel
1616
test -z "$(git ls-files -u)" ||
1717
die "You are in the middle of a conflicted merge."
1818

19-
strategy_args= no_stat= no_commit= squash= no_ff= log_arg= verbosity=
19+
strategy_args= diffstat= no_commit= squash= no_ff= log_arg= verbosity=
2020
curr_branch=$(git symbolic-ref -q HEAD)
2121
curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
2222
rebase=$(git config --bool branch.$curr_branch_short.rebase)
@@ -28,9 +28,9 @@ do
2828
-v|--verbose)
2929
verbosity="$verbosity -v" ;;
3030
-n|--no-stat|--no-summary)
31-
no_stat=-n ;;
31+
diffstat=--no-stat ;;
3232
--stat|--summary)
33-
no_stat=$1 ;;
33+
diffstat=--stat ;;
3434
--log|--no-log)
3535
log_arg=$1 ;;
3636
--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
@@ -188,7 +188,7 @@ fi
188188

189189
merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
190190
test true = "$rebase" &&
191-
exec git-rebase $strategy_args --onto $merge_head \
191+
exec git-rebase $diffstat $strategy_args --onto $merge_head \
192192
${oldremoteref:-$merge_head}
193-
exec git-merge $no_stat $no_commit $squash $no_ff $log_arg $strategy_args \
193+
exec git-merge $diffstat $no_commit $squash $no_ff $log_arg $strategy_args \
194194
"$merge_name" HEAD $merge_head $verbosity

git-rebase.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ do_merge=
4646
dotest="$GIT_DIR"/rebase-merge
4747
prec=4
4848
verbose=
49+
diffstat=$(git config --bool rebase.stat)
4950
git_am_opt=
5051
rebase_root=
5152
force_rebase=
@@ -290,8 +291,15 @@ do
290291
esac
291292
do_merge=t
292293
;;
294+
-n|--no-stat)
295+
diffstat=
296+
;;
297+
--stat)
298+
diffstat=t
299+
;;
293300
-v|--verbose)
294301
verbose=t
302+
diffstat=t
295303
;;
296304
--whitespace=*)
297305
git_am_opt="$git_am_opt $1"
@@ -440,18 +448,21 @@ then
440448
fi
441449
fi
442450

443-
if test -n "$verbose"
444-
then
445-
echo "Changes from $mb to $onto:"
446-
# We want color (if set), but no pager
447-
GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
448-
fi
449-
450451
# Detach HEAD and reset the tree
451452
echo "First, rewinding head to replay your work on top of it..."
452453
git checkout -q "$onto^0" || die "could not detach HEAD"
453454
git update-ref ORIG_HEAD $branch
454455

456+
if test -n "$diffstat"
457+
then
458+
if test -n "$verbose"
459+
then
460+
echo "Changes from $mb to $onto:"
461+
fi
462+
# We want color (if set), but no pager
463+
GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
464+
fi
465+
455466
# If the $onto is a proper descendant of the tip of the branch, then
456467
# we just fast forwarded.
457468
if test "$mb" = "$branch"

t/t3406-rebase-message.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ test_expect_success setup '
2222
git checkout topic &&
2323
quick_one A &&
2424
quick_one B &&
25-
quick_one Z
25+
quick_one Z &&
26+
git tag start
2627
2728
'
2829

@@ -41,4 +42,24 @@ test_expect_success 'rebase -m' '
4142
4243
'
4344

45+
test_expect_success 'rebase --stat' '
46+
git reset --hard start
47+
git rebase --stat master >diffstat.txt &&
48+
grep "^ fileX | *1 +$" diffstat.txt
49+
'
50+
51+
test_expect_success 'rebase w/config rebase.stat' '
52+
git reset --hard start
53+
git config rebase.stat true &&
54+
git rebase master >diffstat.txt &&
55+
grep "^ fileX | *1 +$" diffstat.txt
56+
'
57+
58+
test_expect_success 'rebase -n overrides config rebase.stat config' '
59+
git reset --hard start
60+
git config rebase.stat true &&
61+
git rebase -n master >diffstat.txt &&
62+
! grep "^ fileX | *1 +$" diffstat.txt
63+
'
64+
4465
test_done

0 commit comments

Comments
 (0)