@@ -866,152 +866,158 @@ first and then run 'git rebase --continue' again."
866
866
;;
867
867
--)
868
868
shift
869
- test -z " $REBASE_ROOT " -a $# -ge 1 -a $# -le 2 ||
870
- test ! -z " $REBASE_ROOT " -a $# -le 1 || usage
871
- test -d " $DOTEST " &&
872
- die " Interactive rebase already started"
873
-
874
- git var GIT_COMMITTER_IDENT > /dev/null ||
875
- die " You need to set your committer info first"
876
-
877
- if test -z " $REBASE_ROOT "
878
- then
879
- UPSTREAM_ARG=" $1 "
880
- UPSTREAM=$( git rev-parse --verify " $1 " ) || die " Invalid base"
881
- test -z " $ONTO " && ONTO=$UPSTREAM
882
- shift
883
- else
884
- UPSTREAM=
885
- UPSTREAM_ARG=--root
886
- test -z " $ONTO " &&
887
- die " You must specify --onto when using --root"
888
- fi
889
- run_pre_rebase_hook " $UPSTREAM_ARG " " $@ "
890
-
891
- comment_for_reflog start
892
-
893
- require_clean_work_tree " rebase" " Please commit or stash them."
894
-
895
- if test ! -z " $1 "
896
- then
897
- output git checkout " $1 " -- ||
898
- die " Could not checkout $1 "
899
- fi
869
+ break
870
+ ;;
871
+ esac
872
+ shift
873
+ done
900
874
901
- HEAD=$( git rev-parse --verify HEAD) || die " No HEAD?"
902
- mkdir " $DOTEST " || die " Could not create temporary $DOTEST "
875
+ test -z " $REBASE_ROOT " -a $# -ge 1 -a $# -le 2 ||
876
+ test ! -z " $REBASE_ROOT " -a $# -le 1 || usage
877
+ test -d " $DOTEST " &&
878
+ die " Interactive rebase already started"
903
879
904
- : > " $DOTEST " /interactive || die " Could not mark as interactive"
905
- git symbolic-ref HEAD > " $DOTEST " /head-name 2> /dev/null ||
906
- echo " detached HEAD" > " $DOTEST " /head-name
880
+ git var GIT_COMMITTER_IDENT > /dev/null ||
881
+ die " You need to set your committer info first"
907
882
908
- echo $HEAD > " $DOTEST " /head
909
- case " $REBASE_ROOT " in
910
- ' ' )
911
- rm -f " $DOTEST " /rebase-root ;;
912
- * )
913
- : > " $DOTEST " /rebase-root ;;
914
- esac
915
- echo $ONTO > " $DOTEST " /onto
916
- test -z " $STRATEGY " || echo " $STRATEGY " > " $DOTEST " /strategy
917
- test t = " $VERBOSE " && : > " $DOTEST " /verbose
918
- if test t = " $PRESERVE_MERGES "
919
- then
920
- if test -z " $REBASE_ROOT "
921
- then
922
- mkdir " $REWRITTEN " &&
923
- for c in $( git merge-base --all $HEAD $UPSTREAM )
924
- do
925
- echo $ONTO > " $REWRITTEN " /$c ||
926
- die " Could not init rewritten commits"
927
- done
928
- else
929
- mkdir " $REWRITTEN " &&
930
- echo $ONTO > " $REWRITTEN " /root ||
931
- die " Could not init rewritten commits"
932
- fi
933
- # No cherry-pick because our first pass is to determine
934
- # parents to rewrite and skipping dropped commits would
935
- # prematurely end our probe
936
- MERGES_OPTION=
937
- first_after_upstream=" $( git rev-list --reverse --first-parent $UPSTREAM ..$HEAD | head -n 1) "
938
- else
939
- MERGES_OPTION=" --no-merges --cherry-pick"
940
- fi
941
-
942
- SHORTHEAD=$( git rev-parse --short $HEAD )
943
- SHORTONTO=$( git rev-parse --short $ONTO )
944
- if test -z " $REBASE_ROOT "
945
- # this is now equivalent to ! -z "$UPSTREAM"
946
- then
947
- SHORTUPSTREAM=$( git rev-parse --short $UPSTREAM )
948
- REVISIONS=$UPSTREAM ...$HEAD
949
- SHORTREVISIONS=$SHORTUPSTREAM ..$SHORTHEAD
950
- else
951
- REVISIONS=$ONTO ...$HEAD
952
- SHORTREVISIONS=$SHORTHEAD
953
- fi
954
- git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
955
- --abbrev=7 --reverse --left-right --topo-order \
956
- $REVISIONS | \
957
- sed -n " s/^>//p" |
958
- while read -r shortsha1 rest
883
+ if test -z " $REBASE_ROOT "
884
+ then
885
+ UPSTREAM_ARG=" $1 "
886
+ UPSTREAM=$( git rev-parse --verify " $1 " ) || die " Invalid base"
887
+ test -z " $ONTO " && ONTO=$UPSTREAM
888
+ shift
889
+ else
890
+ UPSTREAM=
891
+ UPSTREAM_ARG=--root
892
+ test -z " $ONTO " &&
893
+ die " You must specify --onto when using --root"
894
+ fi
895
+ run_pre_rebase_hook " $UPSTREAM_ARG " " $@ "
896
+
897
+ comment_for_reflog start
898
+
899
+ require_clean_work_tree " rebase" " Please commit or stash them."
900
+
901
+ if test ! -z " $1 "
902
+ then
903
+ output git checkout " $1 " -- ||
904
+ die " Could not checkout $1 "
905
+ fi
906
+
907
+ HEAD=$( git rev-parse --verify HEAD) || die " No HEAD?"
908
+ mkdir " $DOTEST " || die " Could not create temporary $DOTEST "
909
+
910
+ : > " $DOTEST " /interactive || die " Could not mark as interactive"
911
+ git symbolic-ref HEAD > " $DOTEST " /head-name 2> /dev/null ||
912
+ echo " detached HEAD" > " $DOTEST " /head-name
913
+
914
+ echo $HEAD > " $DOTEST " /head
915
+ case " $REBASE_ROOT " in
916
+ ' ' )
917
+ rm -f " $DOTEST " /rebase-root ;;
918
+ * )
919
+ : > " $DOTEST " /rebase-root ;;
920
+ esac
921
+ echo $ONTO > " $DOTEST " /onto
922
+ test -z " $STRATEGY " || echo " $STRATEGY " > " $DOTEST " /strategy
923
+ test t = " $VERBOSE " && : > " $DOTEST " /verbose
924
+ if test t = " $PRESERVE_MERGES "
925
+ then
926
+ if test -z " $REBASE_ROOT "
927
+ then
928
+ mkdir " $REWRITTEN " &&
929
+ for c in $( git merge-base --all $HEAD $UPSTREAM )
959
930
do
960
- if test t ! = " $PRESERVE_MERGES "
961
- then
962
- printf ' %s\n' " pick $shortsha1 $rest " >> " $TODO "
963
- else
964
- sha1=$( git rev-parse $shortsha1 )
965
- if test -z " $REBASE_ROOT "
966
- then
967
- preserve=t
968
- for p in $( git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
969
- do
970
- if test -f " $REWRITTEN " /$p -a \( $p ! = $ONTO -o $sha1 = $first_after_upstream \)
971
- then
972
- preserve=f
973
- fi
974
- done
975
- else
976
- preserve=f
977
- fi
978
- if test f = " $preserve "
979
- then
980
- touch " $REWRITTEN " /$sha1
981
- printf ' %s\n' " pick $shortsha1 $rest " >> " $TODO "
982
- fi
983
- fi
931
+ echo $ONTO > " $REWRITTEN " /$c ||
932
+ die " Could not init rewritten commits"
984
933
done
985
-
986
- # Watch for commits that been dropped by --cherry-pick
987
- if test t = " $PRESERVE_MERGES "
934
+ else
935
+ mkdir " $REWRITTEN " &&
936
+ echo $ONTO > " $REWRITTEN " /root ||
937
+ die " Could not init rewritten commits"
938
+ fi
939
+ # No cherry-pick because our first pass is to determine
940
+ # parents to rewrite and skipping dropped commits would
941
+ # prematurely end our probe
942
+ MERGES_OPTION=
943
+ first_after_upstream=" $( git rev-list --reverse --first-parent $UPSTREAM ..$HEAD | head -n 1) "
944
+ else
945
+ MERGES_OPTION=" --no-merges --cherry-pick"
946
+ fi
947
+
948
+ SHORTHEAD=$( git rev-parse --short $HEAD )
949
+ SHORTONTO=$( git rev-parse --short $ONTO )
950
+ if test -z " $REBASE_ROOT "
951
+ # this is now equivalent to ! -z "$UPSTREAM"
952
+ then
953
+ SHORTUPSTREAM=$( git rev-parse --short $UPSTREAM )
954
+ REVISIONS=$UPSTREAM ...$HEAD
955
+ SHORTREVISIONS=$SHORTUPSTREAM ..$SHORTHEAD
956
+ else
957
+ REVISIONS=$ONTO ...$HEAD
958
+ SHORTREVISIONS=$SHORTHEAD
959
+ fi
960
+ git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
961
+ --abbrev=7 --reverse --left-right --topo-order \
962
+ $REVISIONS | \
963
+ sed -n " s/^>//p" |
964
+ while read -r shortsha1 rest
965
+ do
966
+ if test t ! = " $PRESERVE_MERGES "
967
+ then
968
+ printf ' %s\n' " pick $shortsha1 $rest " >> " $TODO "
969
+ else
970
+ sha1=$( git rev-parse $shortsha1 )
971
+ if test -z " $REBASE_ROOT "
988
972
then
989
- mkdir " $DROPPED "
990
- # Save all non-cherry-picked changes
991
- git rev-list $REVISIONS --left-right --cherry-pick | \
992
- sed -n " s/^>//p" > " $DOTEST " /not-cherry-picks
993
- # Now all commits and note which ones are missing in
994
- # not-cherry-picks and hence being dropped
995
- git rev-list $REVISIONS |
996
- while read rev
973
+ preserve=t
974
+ for p in $( git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
997
975
do
998
- if test -f " $REWRITTEN " /$rev -a " $( sane_grep " $rev " " $DOTEST " /not-cherry-picks ) " = " "
976
+ if test -f " $REWRITTEN " /$p -a \( $p ! = $ONTO -o $sha1 = $first_after_upstream \)
999
977
then
1000
- # Use -f2 because if rev-list is telling us this commit is
1001
- # not worthwhile, we don't want to track its multiple heads,
1002
- # just the history of its first-parent for others that will
1003
- # be rebasing on top of it
1004
- git rev-list --parents -1 $rev | cut -d' ' -s -f2 > " $DROPPED " /$rev
1005
- short=$( git rev-list -1 --abbrev-commit --abbrev=7 $rev )
1006
- sane_grep -v " ^[a-z][a-z]* $short " < " $TODO " > " ${TODO} 2" ; mv " ${TODO} 2" " $TODO "
1007
- rm " $REWRITTEN " /$rev
978
+ preserve=f
1008
979
fi
1009
980
done
981
+ else
982
+ preserve=f
983
+ fi
984
+ if test f = " $preserve "
985
+ then
986
+ touch " $REWRITTEN " /$sha1
987
+ printf ' %s\n' " pick $shortsha1 $rest " >> " $TODO "
1010
988
fi
989
+ fi
990
+ done
1011
991
1012
- test -s " $TODO " || echo noop >> " $TODO "
1013
- test -n " $AUTOSQUASH " && rearrange_squash " $TODO "
1014
- cat >> " $TODO " << EOF
992
+ # Watch for commits that been dropped by --cherry-pick
993
+ if test t = " $PRESERVE_MERGES "
994
+ then
995
+ mkdir " $DROPPED "
996
+ # Save all non-cherry-picked changes
997
+ git rev-list $REVISIONS --left-right --cherry-pick | \
998
+ sed -n " s/^>//p" > " $DOTEST " /not-cherry-picks
999
+ # Now all commits and note which ones are missing in
1000
+ # not-cherry-picks and hence being dropped
1001
+ git rev-list $REVISIONS |
1002
+ while read rev
1003
+ do
1004
+ if test -f " $REWRITTEN " /$rev -a " $( sane_grep " $rev " " $DOTEST " /not-cherry-picks) " = " "
1005
+ then
1006
+ # Use -f2 because if rev-list is telling us this commit is
1007
+ # not worthwhile, we don't want to track its multiple heads,
1008
+ # just the history of its first-parent for others that will
1009
+ # be rebasing on top of it
1010
+ git rev-list --parents -1 $rev | cut -d' ' -s -f2 > " $DROPPED " /$rev
1011
+ short=$( git rev-list -1 --abbrev-commit --abbrev=7 $rev )
1012
+ sane_grep -v " ^[a-z][a-z]* $short " < " $TODO " > " ${TODO} 2" ; mv " ${TODO} 2" " $TODO "
1013
+ rm " $REWRITTEN " /$rev
1014
+ fi
1015
+ done
1016
+ fi
1017
+
1018
+ test -s " $TODO " || echo noop >> " $TODO "
1019
+ test -n " $AUTOSQUASH " && rearrange_squash " $TODO "
1020
+ cat >> " $TODO " << EOF
1015
1021
1016
1022
# Rebase $SHORTREVISIONS onto $SHORTONTO
1017
1023
#
@@ -1028,22 +1034,18 @@ first and then run 'git rebase --continue' again."
1028
1034
#
1029
1035
EOF
1030
1036
1031
- has_action " $TODO " ||
1032
- die_abort " Nothing to do"
1037
+ has_action " $TODO " ||
1038
+ die_abort " Nothing to do"
1033
1039
1034
- cp " $TODO " " $TODO " .backup
1035
- git_editor " $TODO " ||
1036
- die_abort " Could not execute editor"
1040
+ cp " $TODO " " $TODO " .backup
1041
+ git_editor " $TODO " ||
1042
+ die_abort " Could not execute editor"
1037
1043
1038
- has_action " $TODO " ||
1039
- die_abort " Nothing to do"
1044
+ has_action " $TODO " ||
1045
+ die_abort " Nothing to do"
1040
1046
1041
- test -d " $REWRITTEN " || test -n " $NEVER_FF " || skip_unnecessary_picks
1047
+ test -d " $REWRITTEN " || test -n " $NEVER_FF " || skip_unnecessary_picks
1042
1048
1043
- output git checkout $ONTO || die_abort " could not detach HEAD"
1044
- git update-ref ORIG_HEAD $HEAD
1045
- do_rest
1046
- ;;
1047
- esac
1048
- shift
1049
- done
1049
+ output git checkout $ONTO || die_abort " could not detach HEAD"
1050
+ git update-ref ORIG_HEAD $HEAD
1051
+ do_rest
0 commit comments