-
Notifications
You must be signed in to change notification settings - Fork 7
/
branch
executable file
·126 lines (114 loc) · 2.68 KB
/
branch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/rc -e
rfork en
. /sys/lib/git/common.rc
gitup
flagfmt='a:listall, b:baseref ref, d:delete, n:newbr, s:stay, m:merge, M:nomod'
args='[branch]'
eval `''{aux/getflags $*} || exec aux/usage
modified=()
deleted=()
if(~ $#* 0){
if(~ $#listall 0)
awk '$1=="branch"{print $2}' < $gitfs/ctl
if not
cd .git/refs/ && walk -f heads remotes
exit
}
if(! ~ $#* 1)
exec aux/usage
branch=$1
if(~ $branch refs/heads/*)
new=$name
if not if(~ $branch heads/*)
new=refs/$branch
if not
new=refs/heads/$branch
orig=`{git/query HEAD}
if (~ $#baseref 1)
base=`{git/query $baseref} || exit 'bad base'
if not if(~ $#newbr 0)
base=`{git/query $new}
if not
base=`{git/query HEAD}
if(~ $#newbr 0){
if(! ~ $#baseref 0)
die update would clobber $branch with $baseref
baseref=`$nl{echo -n $new | sed s@refs/heads/@refs/remotes/origin/@}
if(! test -e .git/$new)
if(! base=`{git/query $baseref})
die could not find branch $branch
}
modified=`$nl{git/query -c HEAD $base | grep '^[^-]' | subst '^..'}
deleted=`$nl{git/query -c HEAD $base | grep '^-' | subst '^..'}
# if we delete the current branch without switching, bad things happen
if(~ $delete 1 && ~ `{git/query HEAD} `{git/query $branch})
die 'cannot delete current branch'
# if we're not merging, don't clobber existing changes.
if(~ $#merge 0 && ~ $#delete 0){
if(! ~ $#modified 0 || ! ~ $#deleted 0){
git/walk -fRMA $modified $deleted ||
die 'uncommitted changes would be clobbered'
}
}
if(~ $delete 1){
rm -f .git/$new
echo 'deleted branch' $new
exit
}
commit=`{git/query $base} || die 'branch does not exist:' $base
if(~ $new */*)
mkdir -p .git/`{basename -d $new}
if(! ~ $#stay 0){
echo $commit > .git/$new
exit
}
basedir=`{git/query -p $base}
dirtypaths=()
if(! ~ $#modified 0 || ! ~ $#deleted 0)
dirtypaths=`$nl{git/walk -cfRMA $modified $deleted}
if(~ $#dirtypaths 0)
cleanpaths=($modified $deleted)
if not {
cleanpaths=()
for(p in $modified $deleted)
if(! ~ $p $dirtypaths)
cleanpaths=($cleanpaths $p)
}
echo $commit > .git/$new
for(m in $cleanpaths){
d=`$nl{basename -d $m}
mkdir -p $d
# Modifications can turn a file into
# a directory, or vice versa, so we
# need to delete and copy the files
# over.
a=dir
b=dir
if(test -f $m)
a=file
if(test -f $basedir/tree/$m)
b=file
if(! ~ $a $b){
rm -rf $m
echo R NOQID 0 $m >> .git/INDEX9
}
if(~ $b file){
cp -x -- $basedir/tree/$m $m
echo T NOQID 0 $m >> .git/INDEX9
touch $m
}
}
for(ours in $dirtypaths){
common=$gitfs/object/$orig/tree/$ours
theirs=$gitfs/object/$base/tree/$ours
merge1 $ours $ours $common $theirs
}
for(d in $deleted){
if(! test -d $d){
rm -f $d
echo R NOQID 0 $d >> .git/INDEX9
}
}
echo ref: $new > .git/HEAD
echo $new: `{git/query $new}
exit ''