🌐 AI搜索 & 代理 主页
blob: 6ac961e6d18b8419abdaa5ed57a55ef58f7bc0fb [file] [log] [blame]
Linus Torvalds37f1a512005-07-12 04:30:231#!/bin/sh
2
Fredrik Kuivinen075dd8e2006-01-29 14:02:513USAGE='[(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]]'
Fredrik Kuivinend0255242005-12-11 09:55:494LONG_USAGE='If no arguments, show available branches and mark current branch with a star.
Amos Waterlanda3b427b2005-09-08 02:13:265If one argument, create a new branch <branchname> based off of current HEAD.
Fredrik Kuivinend0255242005-12-11 09:55:496If two arguments, create a new branch <branchname> based off of <start-point>.'
7
8SUBDIRECTORY_OK='Yes'
9. git-sh-setup
Amos Waterlanda3b427b2005-09-08 02:13:2610
Junio C Hamano9cc25272005-11-28 07:16:1511headref=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
Junio C Hamanoeb777612005-11-11 19:12:5012
Junio C Hamanoba65af92005-09-14 08:43:5313delete_branch () {
Junio C Hamano03feddd2005-10-14 01:57:3914 option="$1"
15 shift
Junio C Hamano03feddd2005-10-14 01:57:3916 for branch_name
17 do
18 case ",$headref," in
19 ",$branch_name,")
20 die "Cannot delete the branch you are on." ;;
21 ,,)
22 die "What branch are you on anyway?" ;;
23 esac
24 branch=$(cat "$GIT_DIR/refs/heads/$branch_name") &&
25 branch=$(git-rev-parse --verify "$branch^0") ||
26 die "Seriously, what branch are you talking about?"
27 case "$option" in
28 -D)
Junio C Hamanoba65af92005-09-14 08:43:5329 ;;
30 *)
Junio C Hamano03feddd2005-10-14 01:57:3931 mbs=$(git-merge-base -a "$branch" HEAD | tr '\012' ' ')
32 case " $mbs " in
33 *' '$branch' '*)
34 # the merge base of branch and HEAD contains branch --
Junio C Hamano01385e22005-12-17 07:12:3335 # which means that the HEAD contains everything in both.
Junio C Hamano03feddd2005-10-14 01:57:3936 ;;
37 *)
38 echo >&2 "The branch '$branch_name' is not a strict subset of your current HEAD.
Junio C Hamano01385e22005-12-17 07:12:3339If you are sure you want to delete it, run 'git branch -D $branch_name'."
Junio C Hamano03feddd2005-10-14 01:57:3940 exit 1
41 ;;
42 esac
Junio C Hamanoba65af92005-09-14 08:43:5343 ;;
44 esac
Junio C Hamano03feddd2005-10-14 01:57:3945 rm -f "$GIT_DIR/refs/heads/$branch_name"
46 echo "Deleted branch $branch_name."
47 done
Junio C Hamanoba65af92005-09-14 08:43:5348 exit 0
49}
50
Junio C Hamanoeb777612005-11-11 19:12:5051force=
Junio C Hamanoba65af92005-09-14 08:43:5352while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac
53do
54 case "$1" in
55 -d | -D)
Junio C Hamano03feddd2005-10-14 01:57:3956 delete_branch "$@"
Junio C Hamanoba65af92005-09-14 08:43:5357 exit
58 ;;
Junio C Hamanoeb777612005-11-11 19:12:5059 -f)
60 force="$1"
61 ;;
Junio C Hamanoba65af92005-09-14 08:43:5362 --)
63 shift
64 break
65 ;;
66 -*)
67 usage
68 ;;
69 esac
70 shift
71done
72
Kalle Valoe4aec262005-08-16 17:58:1073case "$#" in
740)
Kalle Valoe4aec262005-08-16 17:58:1075 git-rev-parse --symbolic --all |
76 sed -ne 's|^refs/heads/||p' |
77 sort |
78 while read ref
79 do
80 if test "$headref" = "$ref"
81 then
82 pfx='*'
83 else
84 pfx=' '
85 fi
86 echo "$pfx $ref"
87 done
88 exit 0 ;;
891)
Junio C Hamanoa38e7272005-07-23 02:08:4790 head=HEAD ;;
Kalle Valoe4aec262005-08-16 17:58:10912)
Junio C Hamanoa38e7272005-07-23 02:08:4792 head="$2^0" ;;
93esac
Kalle Valoe4aec262005-08-16 17:58:1094branchname="$1"
Amos Waterlanda3b427b2005-09-08 02:13:2695
Junio C Hamanoff84d322005-08-24 21:31:3696rev=$(git-rev-parse --verify "$head") || exit
Linus Torvalds37f1a512005-07-12 04:30:2397
Junio C Hamano03feddd2005-10-14 01:57:3998git-check-ref-format "heads/$branchname" ||
99 die "we do not like '$branchname' as a branch name."
Linus Torvalds37f1a512005-07-12 04:30:23100
Junio C Hamanoeb777612005-11-11 19:12:50101if [ -e "$GIT_DIR/refs/heads/$branchname" ]
102then
103 if test '' = "$force"
104 then
105 die "$branchname already exists."
106 elif test "$branchname" = "$headref"
107 then
108 die "cannot force-update the current branch."
109 fi
110fi
Alex Riesen08db81a2005-11-14 22:10:59111git update-ref "refs/heads/$branchname" $rev