Mercurial > dotfiles
annotate .shell.d/50.vcs_functions.sh @ 532:f452d7f26e04 default tip
vcs_functions: add jj status to current branch info
This causes jj info to show up in my prompt. The first change to this since
2018!
| author | Augie Fackler <raf@durin42.com> |
|---|---|
| date | Sat, 11 Jul 2026 21:28:08 -0400 |
| parents | fff281929b47 |
| children |
| rev | line source |
|---|---|
| 0 | 1 ## vcs_functions |
| 2 # This file contains a handful of functions that relate to using some version | |
| 3 # control tool or other. | |
| 4 | |
|
133
5b0b8ad2cb2c
vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents:
129
diff
changeset
|
5 function ezsvnsync() { |
|
169
040ac89ffe1e
ez-svn-sync: add usage help
Augie Fackler <durin42@gmail.com>
parents:
167
diff
changeset
|
6 if [ x"$1" = "x" ] ; then |
|
040ac89ffe1e
ez-svn-sync: add usage help
Augie Fackler <durin42@gmail.com>
parents:
167
diff
changeset
|
7 echo 'usage: ez-svn-sync repo url' |
|
040ac89ffe1e
ez-svn-sync: add usage help
Augie Fackler <durin42@gmail.com>
parents:
167
diff
changeset
|
8 return 0 |
|
040ac89ffe1e
ez-svn-sync: add usage help
Augie Fackler <durin42@gmail.com>
parents:
167
diff
changeset
|
9 fi |
|
63
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
10 local repo |
|
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
11 repo=$1 |
|
169
040ac89ffe1e
ez-svn-sync: add usage help
Augie Fackler <durin42@gmail.com>
parents:
167
diff
changeset
|
12 local url |
|
63
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
13 url=$2 |
|
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
14 svnadmin create $repo |
|
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
15 echo '#!/bin/sh' >> $repo/hooks/pre-revprop-change |
|
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
16 echo 'exit 0' >> $repo/hooks/pre-revprop-change |
|
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
17 chmod +x $repo/hooks/pre-revprop-change |
|
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
18 svnsync init file://`pwd`/$repo $url |
|
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
19 svnsync sync file://`pwd`/$repo |
|
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
20 } |
|
133
5b0b8ad2cb2c
vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents:
129
diff
changeset
|
21 alias ez-svn-sync=ezsvnsync |
|
63
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
22 |
| 0 | 23 # Function to grab the url of an svn wc |
| 24 function svnurlof() { | |
| 25 local url | |
| 26 url=`svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
| 27 if [ x"$url" = "x" ] ; then | |
| 28 url=`git svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
| 29 fi | |
| 30 if [ x"$url" = "x" ] ; then | |
|
46
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
31 local dir |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
32 dir=$1 |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
33 if [ x"$dir" = "x" ] ; then |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
34 dir="." |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
35 fi |
| 0 | 36 url=`hg -R $dir svn info 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` |
| 37 fi | |
| 38 if [ x"$url" = "x" ] ; then | |
|
167
f485c32913cd
vcs functions: refer to hgsubversion by the real name
Augie Fackler <durin42@gmail.com>
parents:
156
diff
changeset
|
39 echo -n 'No repo found (tried svn, git-svn, hgsubversion)' |
| 0 | 40 fi |
| 41 echo $url | |
| 42 } | |
| 43 | |
| 44 # Function to clean locks out of svn wcs | |
| 45 function clean_svn_source_trees() { | |
| 46 for aa in */ ; do | |
| 47 pushd $aa > /dev/null | |
| 48 if [ -e .svn ] ; then | |
| 49 echo $aa 'is an svn checkout, cleaning' && svn cleanup | |
| 50 fi | |
| 51 popd > /dev/null | |
| 52 done | |
| 53 } | |
| 54 | |
| 55 # Function to update source trees of known VCS tools in the working dir. | |
| 56 # "known" means ones I'm forced to use on a regular basis | |
| 57 function update_source_trees() { | |
|
184
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
58 if ! ls -l | egrep ^d > /dev/null ; then |
|
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
59 ls -l | egrep ^d |
|
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
60 return |
|
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
61 fi |
|
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
62 local hgpath |
| 0 | 63 for aa in */ ; do |
|
31
a5691a22c92b
Fix a bug in update_source_trees where it could eat any existing dirstack
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
64 pushd $aa > /dev/null || continue |
| 0 | 65 if [ -e .svn ] ; then |
| 66 echo $aa 'is an svn checkout, updating' | |
| 67 svn up | |
|
115
5f00625aa1ed
Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents:
83
diff
changeset
|
68 elif [ -e README.txt ] \ |
|
5f00625aa1ed
Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents:
83
diff
changeset
|
69 && [ -e format ] \ |
|
5f00625aa1ed
Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents:
83
diff
changeset
|
70 && grep "This is a Subversion repository; use the 'svnadmin' tool to examine" README.txt > /dev/null \ |
|
5f00625aa1ed
Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents:
83
diff
changeset
|
71 && svn pl --revprop -r 0 file://$(pwd) | fgrep svn:sync-from-url > /dev/null\ |
|
5f00625aa1ed
Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents:
83
diff
changeset
|
72 ; then |
|
5f00625aa1ed
Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents:
83
diff
changeset
|
73 echo "$aa looks like an svnsync clone, syncing" |
|
5f00625aa1ed
Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents:
83
diff
changeset
|
74 svnsync sync file://$(pwd) |
| 0 | 75 elif [ -e .git/svn ] ; then |
| 76 echo $aa 'is a git-svn checkout, updating' | |
| 77 git svn fetch | |
| 78 elif [ -e .git ] ; then | |
| 79 echo $aa 'is a git checkout, updating' | |
|
233
da06f9fd5016
update-source-trees: git fetch all remotes instead of doing git pull origin master
Augie Fackler <durin42@gmail.com>
parents:
210
diff
changeset
|
80 for remote in $(git remote) ; do |
|
da06f9fd5016
update-source-trees: git fetch all remotes instead of doing git pull origin master
Augie Fackler <durin42@gmail.com>
parents:
210
diff
changeset
|
81 git fetch $remote |
|
da06f9fd5016
update-source-trees: git fetch all remotes instead of doing git pull origin master
Augie Fackler <durin42@gmail.com>
parents:
210
diff
changeset
|
82 done |
| 0 | 83 elif [ -e .hg ] ; then |
|
184
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
84 echo $aa 'is an hg checkout, updating' |
|
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
85 for hgpath in $(HGRCPATH=/dev/null hg paths | sed 's/.* = //g' | sort | uniq ) ; do |
|
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
86 hg pull --update $hgpath |
|
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
87 done |
|
35
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
88 if [ -e .hg/patches/.hg ] ; then |
|
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
89 echo $aa 'has an mq, updating that too...' |
|
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
90 hg -R .hg/patches pull -u |
|
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
91 fi |
| 0 | 92 elif [ -e _MTN ] ; then |
| 93 echo $aa "is an mtn co, updating" && mtn pull && mtn up | |
|
184
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
94 else |
|
efa2bfc73d2d
update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents:
169
diff
changeset
|
95 update_source_trees |
| 0 | 96 fi |
| 97 popd > /dev/null | |
| 98 done | |
| 99 } | |
|
115
5f00625aa1ed
Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents:
83
diff
changeset
|
100 alias update-source-trees=update_source_trees |
| 0 | 101 |
| 102 function vcs_current_branch() { | |
|
532
f452d7f26e04
vcs_functions: add jj status to current branch info
Augie Fackler <raf@durin42.com>
parents:
462
diff
changeset
|
103 local jjrev="$(jj log -r @ --no-graph -T 'change_id.shortest() ++ if(empty, "*", "")')" |
|
f452d7f26e04
vcs_functions: add jj status to current branch info
Augie Fackler <raf@durin42.com>
parents:
462
diff
changeset
|
104 if [ ! -z "$jjrev" ] ; then |
|
f452d7f26e04
vcs_functions: add jj status to current branch info
Augie Fackler <raf@durin42.com>
parents:
462
diff
changeset
|
105 echo "jj $jjrev" |
|
f452d7f26e04
vcs_functions: add jj status to current branch info
Augie Fackler <raf@durin42.com>
parents:
462
diff
changeset
|
106 return 0 |
|
f452d7f26e04
vcs_functions: add jj status to current branch info
Augie Fackler <raf@durin42.com>
parents:
462
diff
changeset
|
107 fi |
|
10
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
108 git branch 2> /dev/null > /dev/null |
| 0 | 109 if [ $? = 0 ] ; then |
| 110 git branch --verbose | grep '^*' | sed 's/* //;s/ /:/;s/ .*//;s/:/ /' | |
| 111 return 0 | |
| 112 fi | |
| 113 # when wc-ng comes out, we'll probably do the following | |
| 114 # svn info 2> /dev/null > /dev/null | |
| 115 if [ -e .svn ] ; then | |
| 116 local d=`svn info | grep URL | sed 's/.*://'` | |
| 117 local br=`echo $d | awk '{ | |
| 118 if ( index($1, "trunk") ) { | |
| 119 print "trunk" | |
| 120 } else { | |
| 121 x = index($1, "branches") ; | |
| 122 if ( x != 0 ) { | |
| 123 sub(".*/branches/", ""); | |
| 124 sub("/.*", ""); | |
| 125 print $0 | |
| 126 } | |
| 127 } | |
| 128 }'` | |
| 129 local rev=`svn info | grep Revision | sed 's/.*: /r/'` | |
| 130 echo $br $rev | |
| 131 return 0 | |
| 132 fi | |
|
462
fff281929b47
shrc: set HGPLAIN in prompt scaffolding
Augie Fackler <raf@durin42.com>
parents:
396
diff
changeset
|
133 hginfo=$(HGPLAIN=1 hg log --config extensions.blackbox='!' -r . -T'{if(activebookmark,"{activebookmark}","{branch}")} {shortest(node)}' 2>/dev/null) |
|
10
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
134 if [ $? = 0 ] ; then |
|
363
51aaf8bcd6ec
vcs_functions: fix vcs_current_branch to use hg templating
Augie Fackler <raf@durin42.com>
parents:
298
diff
changeset
|
135 echo "$hginfo" |
|
10
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
136 return 0 |
|
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
137 fi |
| 0 | 138 return 1 |
| 139 } | |
| 140 | |
|
283
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
141 function find_dvcs_root() { |
|
462
fff281929b47
shrc: set HGPLAIN in prompt scaffolding
Augie Fackler <raf@durin42.com>
parents:
396
diff
changeset
|
142 local hgroot=`HGPLAIN=1 hg root 2> /dev/null` |
|
283
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
143 local gitroot=$(git rev-parse --show-toplevel 2> /dev/null) |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
144 local hglen=$(expr length $hgroot) |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
145 local gitlen=$(expr length $gitroot) |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
146 if [ $hglen -ge $gitlen ] ; then |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
147 if [ -n "$hgroot" ] ; then |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
148 echo $hgroot |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
149 return 0 |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
150 fi |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
151 else |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
152 if [ -n "$gitroot" ] ; then |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
153 echo $gitroot |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
154 return 0 |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
155 fi |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
156 fi |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
157 return 1 |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
158 } |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
159 |
| 0 | 160 # change to the root dir of the current wc |
| 161 function wcroot() { | |
|
283
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
162 local dvcsroot=$(find_dvcs_root) |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
163 if [ -n $dvcsroot ] ; then |
|
533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
Augie Fackler <durin42@gmail.com>
parents:
262
diff
changeset
|
164 cd $dvcsroot |
| 0 | 165 return 0 |
| 166 fi | |
| 167 if [ -e .svn ] ; then | |
| 168 while [ -e ../.svn ] ; do | |
| 169 cd .. | |
| 170 done | |
| 171 return 0 | |
| 172 fi | |
| 173 echo No working copy found'!' | |
| 174 } |
