File tree Expand file tree Collapse file tree 8 files changed +104
-9
lines changed Expand file tree Collapse file tree 8 files changed +104
-9
lines changed Original file line number Diff line number Diff line change 1
1
# !/bin/env janet
2
- (use ./interactive-sparse-checkout )
2
+ (use .. /interactive-sparse-checkout )
3
3
(defn main [_ & args ]
4
4
(interactive-sparse-checkout ))
Original file line number Diff line number Diff line change
1
+ # !/bin/env janet
2
+ (import spork/argparse :prefix " " )
3
+ (use ../interactive-sparse-clone )
4
+
5
+ (def argparse-params
6
+ [` Clone repo and sparse check it out interactively`
7
+ " ref" {:kind :option
8
+ :short " r"
9
+ :default " origin/main"
10
+ :help " Ref to check out" }
11
+ :default {:kind :accumulate
12
+ :help " remote to clone and optionally a path to clone it to" }])
13
+
14
+ (defn main [_ remote & args ]
15
+ (def res (argparse ;argparse-params ))
16
+ (unless res (os/exit 1 ))
17
+
18
+ (interactive-sparse-clone (first (res :default ))
19
+ :ref (res " ref" )
20
+ :path (get (res :default ) 1 nil )))
Original file line number Diff line number Diff line change 1
1
# !/bin/env janet
2
- (use ./repl )
2
+ (use .. /repl )
3
3
(defn main [& _ ]
4
4
(repl ))
Original file line number Diff line number Diff line change 16
16
ret )
17
17
[])) # Ignore top level or empty paths
18
18
19
- (defn interactive-sparse-checkout []
19
+ (defn interactive-sparse-checkout
20
+ ` Interactivly select paths to sparse checkout in a git repo using a fuzzy file selection ui
21
+ ref optionally defines the reference to use to look up the tree of files and later checkout
22
+ git-repo-path optionally passes the repo directory and is passed to git via the -C option`
23
+ [&named ref git-repo-path ]
24
+ (default ref " HEAD" )
25
+ (def extra-git-opts @[])
26
+ (when git-repo-path
27
+ (array/push extra-git-opts " -C" )
28
+ (array/push extra-git-opts git-repo-path ))
20
29
(def selected-paths @[])
21
30
(def available-paths
22
- (->> (sh/exec-slurp " git" " ls-tree" " --name-only" " -r" " -z" " HEAD " )
31
+ (->> (sh/exec-slurp " git" ; extra-git-opts " ls-tree" " --name-only" " -r" " -z" ref )
23
32
(string/split " \0 " )
24
33
(mapcat filter-and-split-paths-into-components )
25
34
(distinct )))
26
- (exec " git" " sparse-checkout" " set" ;(jeff/choose available-paths :multi true ))
27
- (exec " git" " checkout" " HEAD" ))
35
+ # TODO support second ui that allows specifying patterns and shows the matching files in a second window or smth like that
36
+ (exec " git" ;extra-git-opts " sparse-checkout" " set" ;(jeff/choose available-paths :multi true ))
37
+ (exec " git" ;extra-git-opts " checkout" ref ))
Original file line number Diff line number Diff line change
1
+ # !/bin/env janet
2
+ # (import spork/path)
3
+ # (import spork/sh)
4
+ (import ./remote )
5
+ (use ./interactive-sparse-checkout )
6
+ (use ./exec )
7
+
8
+ (defn interactive-sparse-clone [remote &named path ref ]
9
+ (default path (remote/get-name remote ))
10
+ (default ref " origin/main" )
11
+
12
+ (os/mkdir path )
13
+ (exec " git" " -C" path " init" )
14
+ (exec " git" " -C" path " remote" " add" " origin" remote )
15
+ (exec " git" " -C" path " fetch" " --depth" " 1" " origin" " HEAD" )
16
+ (exec " git" " -C" path " fetch" )
17
+ (interactive-sparse-checkout :git-repo-path path :ref ref ))
Original file line number Diff line number Diff line change
1
+ (import uri )
2
+ (import ./string )
3
+
4
+ (def remote-scp-peg
5
+ (peg/compile
6
+ ~{:user (capture (to " @" ))
7
+ :host (capture (to " :" ))
8
+ :path-part (* (capture (to (+ " /" -1 ))) (+ " /" -1 ))
9
+ :path (replace (some :path-part )
10
+ ,(fn [& x ] x ))
11
+ :main (replace (* :user " @" :host " :" :path )
12
+ ,|{:user $0
13
+ :host $1
14
+ :path $2 })}))
15
+
16
+ (defn- remote/parse
17
+ ` Parse remote url into it's components`
18
+ [remote ]
19
+ (def peg-res (first (peg/match remote-scp-peg remote )))
20
+ (if peg-res
21
+ {:scheme " scp" :host (peg-res :host ) :path (peg-res :path ) :user (peg-res :user )}
22
+ (let [uri-res (uri/parse remote )]
23
+ {:scheme (uri-res :scheme )
24
+ :host (uri-res :host )
25
+ :user (uri-res :userinfo )
26
+ :path (first (peg/match ~{:path-part (* (capture (to (+ " /" -1 ))) (+ " /" -1 ))
27
+ :main (replace (* (opt " /" ) (some :path-part ))
28
+ ,(fn [& x ] x ))}
29
+ (uri-res :path )))})))
30
+
31
+ (defn get-name [remote ]
32
+ (string/trim-suffix " .git" (last ((remote/parse remote ) :path ))))
33
+
34
+ (setdyn 'parse (dyn 'remote/parse ))
Original file line number Diff line number Diff line change
1
+ (defn trim-prefix
2
+ " Trim the specified prefix of a string if it has one"
3
+ [prefix str ]
4
+ (if (string/has-prefix? prefix str )
5
+ (slice str (length prefix ) -1 )
6
+ str ))
7
+
8
+ (defn trim-suffix
9
+ " Trim the specified suffix of a string if it has one"
10
+ [suffix str ]
11
+ (if (string/has-suffix? suffix str )
12
+ (slice str 0 (* -1 (+ 1 (length suffix ))))
13
+ str ))
Original file line number Diff line number Diff line change 8
8
:url " https://tasadar.net/tionis/git-tools"
9
9
:repo " git+https://tasadar.net/tionis/git-tools" )
10
10
11
- (each f (filter |( peg/match ~( sequence " git- " ( any 1 ) -1 ) $0 ) ( os/dir " git-tools" ) )
11
+ (each f (os/dir " git-tools/cli " )
12
12
(declare-executable # Install janet git tools
13
- :name f
14
- :entry (string " git-tools/" f )
13
+ :name ( first ( peg/match ~( * ( * ( capture ( any ( * ( not " .janet " ) 1 ))) " .janet " ) -1 ) f ))
14
+ :entry (string " git-tools/cli/ " f )
15
15
:install true ))
16
16
17
17
(each f (os/dir " bin" ) # Install shell scripts
25
25
:is-janet false ))
26
26
27
27
(each f (if (os/stat " man" ) (os/dir " man" ) [])
28
+ # TODO auto generate from module doc if not exists?
28
29
(declare-manpage # Install man pages
29
30
(string " man/" f )))
30
31
You can’t perform that action at this time.
0 commit comments