Skip to content

Commit 43d268e

Browse files
committed
Merge branch 'ch/filter-branch-deprecate-remap-to-ancestor'
* ch/filter-branch-deprecate-remap-to-ancestor: filter-branch: retire --remap-to-ancestor
2 parents d42cb58 + 7ec344d commit 43d268e

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

Documentation/git-filter-branch.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,7 @@ to other tags will be rewritten to point to the underlying commit.
159159
--subdirectory-filter <directory>::
160160
Only look at the history which touches the given subdirectory.
161161
The result will contain that directory (and only that) as its
162-
project root. Implies --remap-to-ancestor.
163-
164-
--remap-to-ancestor::
165-
Rewrite refs to the nearest rewritten ancestor instead of
166-
ignoring them.
167-
+
168-
Normally, positive refs on the command line are only changed if the
169-
commit they point to was rewritten. However, you can limit the extent
170-
of this rewriting by using linkgit:rev-list[1] arguments, e.g., path
171-
limiters. Refs pointing to such excluded commits would then normally
172-
be ignored. With this option, they are instead rewritten to point at
173-
the nearest ancestor that was not excluded.
162+
project root. Implies <<Remap_to_ancestor>>.
174163

175164
--prune-empty::
176165
Some kind of filters will generate empty commits, that left the tree
@@ -204,7 +193,18 @@ the nearest ancestor that was not excluded.
204193
Arguments for 'git rev-list'. All positive refs included by
205194
these options are rewritten. You may also specify options
206195
such as '--all', but you must use '--' to separate them from
207-
the 'git filter-branch' options.
196+
the 'git filter-branch' options. Implies <<Remap_to_ancestor>>.
197+
198+
199+
[[Remap_to_ancestor]]
200+
Remap to ancestor
201+
~~~~~~~~~~~~~~~~~
202+
203+
By using linkgit:rev-list[1] arguments, e.g., path limiters, you can limit the
204+
set of revisions which get rewritten. However, positive refs on the command
205+
line are distinguished: we don't let them be excluded by such limiters. For
206+
this purpose, they are instead rewritten to point at the nearest ancestor that
207+
was not excluded.
208208

209209

210210
Examples

git-filter-branch.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ do
139139
continue
140140
;;
141141
--remap-to-ancestor)
142+
# deprecated ($remap_to_ancestor is set now automatically)
142143
shift
143144
remap_to_ancestor=t
144145
continue
@@ -265,7 +266,14 @@ mkdir ../map || die "Could not create map/ directory"
265266

266267
# we need "--" only if there are no path arguments in $@
267268
nonrevs=$(git rev-parse --no-revs "$@") || exit
268-
test -z "$nonrevs" && dashdash=-- || dashdash=
269+
if test -z "$nonrevs"
270+
then
271+
dashdash=--
272+
else
273+
dashdash=
274+
remap_to_ancestor=t
275+
fi
276+
269277
rev_args=$(git rev-parse --revs-only "$@")
270278

271279
case "$filter_subdir" in

t/t7003-filter-branch.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,24 @@ test_expect_success '--remap-to-ancestor with filename filters' '
307307
test $orig_invariant = $(git rev-parse invariant)
308308
'
309309

310+
test_expect_success 'automatic remapping to ancestor with filename filters' '
311+
git checkout master &&
312+
git reset --hard A &&
313+
test_commit add-foo2 foo 1 &&
314+
git branch moved-foo2 &&
315+
test_commit add-bar2 bar a &&
316+
git branch invariant2 &&
317+
orig_invariant=$(git rev-parse invariant2) &&
318+
git branch moved-bar2 &&
319+
test_commit change-foo2 foo 2 &&
320+
git filter-branch -f \
321+
moved-foo2 moved-bar2 A..master \
322+
-- -- foo &&
323+
test $(git rev-parse moved-foo2) = $(git rev-parse moved-bar2) &&
324+
test $(git rev-parse moved-foo2) = $(git rev-parse master^) &&
325+
test $orig_invariant = $(git rev-parse invariant2)
326+
'
327+
310328
test_expect_success 'setup submodule' '
311329
rm -fr ?* .git &&
312330
git init &&

0 commit comments

Comments
 (0)