Skip to content

Commit

Permalink
Merge branch 'tv/rebase-stat'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed Mar 11, 2009
2 parents 8a396c0 + a334e12 commit e439979
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,10 @@ pull.octopus::
pull.twohead::
The default merge strategy to use when pulling a single branch.

rebase.stat::
Whether to show a diffstat of what changed upstream since the last
rebase. False by default.

receive.fsckObjects::
If it is set to true, git-receive-pack will check all received
objects. It will abort in the case of a malformed object or a
Expand Down
17 changes: 16 additions & 1 deletion Documentation/git-rebase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ Alternatively, you can undo the 'git-rebase' with

git rebase --abort

CONFIGURATION
-------------

rebase.stat::
Whether to show a diffstat of what changed upstream since the last
rebase. False by default.

OPTIONS
-------
<newbase>::
Expand Down Expand Up @@ -232,7 +239,15 @@ OPTIONS

-v::
--verbose::
Display a diffstat of what changed upstream since the last rebase.
Be verbose. Implies --stat.

--stat::
Show a diffstat of what changed upstream since the last rebase. The
diffstat is also controlled by the configuration option rebase.stat.

-n::
--no-stat::
Do not show a diffstat as part of the rebase process.

--no-verify::
This option bypasses the pre-rebase hook. See also linkgit:githooks[5].
Expand Down
10 changes: 5 additions & 5 deletions git-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cd_to_toplevel
test -z "$(git ls-files -u)" ||
die "You are in the middle of a conflicted merge."

strategy_args= no_stat= no_commit= squash= no_ff= log_arg= verbosity=
strategy_args= diffstat= no_commit= squash= no_ff= log_arg= verbosity=
curr_branch=$(git symbolic-ref -q HEAD)
curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
rebase=$(git config --bool branch.$curr_branch_short.rebase)
Expand All @@ -28,9 +28,9 @@ do
-v|--verbose)
verbosity="$verbosity -v" ;;
-n|--no-stat|--no-summary)
no_stat=-n ;;
diffstat=--no-stat ;;
--stat|--summary)
no_stat=$1 ;;
diffstat=--stat ;;
--log|--no-log)
log_arg=$1 ;;
--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
Expand Down Expand Up @@ -188,7 +188,7 @@ fi

merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
test true = "$rebase" &&
exec git-rebase $strategy_args --onto $merge_head \
exec git-rebase $diffstat $strategy_args --onto $merge_head \
${oldremoteref:-$merge_head}
exec git-merge $no_stat $no_commit $squash $no_ff $log_arg $strategy_args \
exec git-merge $diffstat $no_commit $squash $no_ff $log_arg $strategy_args \
"$merge_name" HEAD $merge_head $verbosity
25 changes: 18 additions & 7 deletions git-rebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ do_merge=
dotest="$GIT_DIR"/rebase-merge
prec=4
verbose=
diffstat=$(git config --bool rebase.stat)
git_am_opt=
rebase_root=
force_rebase=
Expand Down Expand Up @@ -290,8 +291,15 @@ do
esac
do_merge=t
;;
-n|--no-stat)
diffstat=
;;
--stat)
diffstat=t
;;
-v|--verbose)
verbose=t
diffstat=t
;;
--whitespace=*)
git_am_opt="$git_am_opt $1"
Expand Down Expand Up @@ -440,18 +448,21 @@ then
fi
fi

if test -n "$verbose"
then
echo "Changes from $mb to $onto:"
# We want color (if set), but no pager
GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
fi

# Detach HEAD and reset the tree
echo "First, rewinding head to replay your work on top of it..."
git checkout -q "$onto^0" || die "could not detach HEAD"
git update-ref ORIG_HEAD $branch

if test -n "$diffstat"
then
if test -n "$verbose"
then
echo "Changes from $mb to $onto:"
fi
# We want color (if set), but no pager
GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
fi

# If the $onto is a proper descendant of the tip of the branch, then
# we just fast forwarded.
if test "$mb" = "$branch"
Expand Down
23 changes: 22 additions & 1 deletion t/t3406-rebase-message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ test_expect_success setup '
git checkout topic &&
quick_one A &&
quick_one B &&
quick_one Z
quick_one Z &&
git tag start
'

Expand All @@ -41,4 +42,24 @@ test_expect_success 'rebase -m' '
'

test_expect_success 'rebase --stat' '
git reset --hard start
git rebase --stat master >diffstat.txt &&
grep "^ fileX | *1 +$" diffstat.txt
'

test_expect_success 'rebase w/config rebase.stat' '
git reset --hard start
git config rebase.stat true &&
git rebase master >diffstat.txt &&
grep "^ fileX | *1 +$" diffstat.txt
'

test_expect_success 'rebase -n overrides config rebase.stat config' '
git reset --hard start
git config rebase.stat true &&
git rebase -n master >diffstat.txt &&
! grep "^ fileX | *1 +$" diffstat.txt
'

test_done

0 comments on commit e439979

Please sign in to comment.