Skip to content

Commit 0b42769

Browse files
author
Junio C Hamano
committed
Merge branches 'jc/branch' and 'jc/rebase'
3 parents f9039f3 + eb77761 + 7f59dbb commit 0b42769

File tree

2 files changed

+34
-63
lines changed

2 files changed

+34
-63
lines changed

git-branch.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
. git-sh-setup || die "Not a git archive"
44

55
usage () {
6-
echo >&2 "usage: $(basename $0)"' [-d <branch>] | [<branch> [start-point]]
6+
echo >&2 "usage: $(basename $0)"' [-d <branch>] | [[-f] <branch> [start-point]]
77
88
If no arguments, show available branches and mark current branch with a star.
99
If one argument, create a new branch <branchname> based off of current HEAD.
@@ -12,11 +12,12 @@ If two arguments, create a new branch <branchname> based off of <start-point>.
1212
exit 1
1313
}
1414

15+
headref=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD |
16+
sed -e 's|^refs/heads/||')
17+
1518
delete_branch () {
1619
option="$1"
1720
shift
18-
headref=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD |
19-
sed -e 's|^refs/heads/||')
2021
for branch_name
2122
do
2223
case ",$headref," in
@@ -52,13 +53,17 @@ delete_branch () {
5253
exit 0
5354
}
5455

56+
force=
5557
while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac
5658
do
5759
case "$1" in
5860
-d | -D)
5961
delete_branch "$@"
6062
exit
6163
;;
64+
-f)
65+
force="$1"
66+
;;
6267
--)
6368
shift
6469
break
@@ -72,8 +77,6 @@ done
7277

7378
case "$#" in
7479
0)
75-
headref=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD |
76-
sed -e 's|^refs/heads/||')
7780
git-rev-parse --symbolic --all |
7881
sed -ne 's|^refs/heads/||p' |
7982
sort |
@@ -97,10 +100,18 @@ branchname="$1"
97100

98101
rev=$(git-rev-parse --verify "$head") || exit
99102

100-
[ -e "$GIT_DIR/refs/heads/$branchname" ] &&
101-
die "$branchname already exists."
102103
git-check-ref-format "heads/$branchname" ||
103104
die "we do not like '$branchname' as a branch name."
104105

106+
if [ -e "$GIT_DIR/refs/heads/$branchname" ]
107+
then
108+
if test '' = "$force"
109+
then
110+
die "$branchname already exists."
111+
elif test "$branchname" = "$headref"
112+
then
113+
die "cannot force-update the current branch."
114+
fi
115+
fi
105116
git update-ref "refs/heads/$branchname" $rev
106117

git-rebase.sh

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,25 @@
55

66
. git-sh-setup || die "Not a git archive."
77

8-
usage="usage: $0 "'<upstream> [<head>]
9-
10-
Uses output from git-cherry to rebase local commits to the new head of
11-
upstream tree.'
12-
13-
case "$#,$1" in
14-
1,*..*)
15-
upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$')
16-
set x "$upstream" "$ours"
17-
shift ;;
18-
esac
8+
# The other head is given
9+
other=$(git-rev-parse --verify "$1^0") || exit
1910

11+
# The tree must be really really clean.
2012
git-update-index --refresh || exit
13+
diff=$(git-diff-index --cached --name-status -r HEAD)
14+
case "$different" in
15+
?*) echo "$diff"
16+
exit 1
17+
;;
18+
esac
2119

20+
# If the branch to rebase is given, first switch to it.
2221
case "$#" in
23-
1) ours_symbolic=HEAD ;;
24-
2) ours_symbolic="$2" ;;
25-
*) die "$usage" ;;
22+
2)
23+
git-checkout "$2" || exit
2624
esac
2725

28-
upstream=`git-rev-parse --verify "$1"` &&
29-
ours=`git-rev-parse --verify "$ours_symbolic"` || exit
30-
different1=$(git-diff-index --name-only --cached "$ours") &&
31-
different2=$(git-diff-index --name-only "$ours") &&
32-
test "$different1$different2" = "" ||
33-
die "Your working tree does not match $ours_symbolic."
34-
35-
git-read-tree -m -u $ours $upstream &&
36-
new_head=$(git-rev-parse --verify "$upstream^0") &&
37-
git-update-ref HEAD "$new_head" || exit
38-
39-
tmp=.rebase-tmp$$
40-
fail=$tmp-fail
41-
trap "rm -rf $tmp-*" 1 2 3 15
42-
43-
>$fail
44-
45-
git-cherry -v $upstream $ours |
46-
while read sign commit msg
47-
do
48-
case "$sign" in
49-
-)
50-
echo >&2 "* Already applied: $msg"
51-
continue ;;
52-
esac
53-
echo >&2 "* Applying: $msg"
54-
S=$(git-rev-parse --verify HEAD) &&
55-
git-cherry-pick --replay $commit || {
56-
echo >&2 "* Not applying the patch and continuing."
57-
echo $commit >>$fail
58-
git-reset --hard $S
59-
}
60-
done
61-
if test -s $fail
62-
then
63-
echo >&2 Some commits could not be rebased, check by hand:
64-
cat >&2 $fail
65-
echo >&2 "(the same list of commits are found in $tmp)"
66-
exit 1
67-
else
68-
rm -f $fail
69-
fi
26+
# Rewind the head to "$other"
27+
git-reset --hard "$other"
28+
git-format-patch -k --stdout --full-index "$other" ORIG_HEAD |
29+
git am --binary -3 -k

0 commit comments

Comments
 (0)