-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-getpin
executable file
·52 lines (38 loc) · 1.18 KB
/
git-getpin
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
#!/usr/bin/tclsh
set dirname [lindex $argv 0]
if { $dirname == "" } {
# No name given - meaning you want to get pin of the submodule
# that you have currently cd'd to.
# First, get to the toplevel git dir
set sub [exec git rev-parse --show-toplevel]
cd $sub
# Now extract the exact name of the submodule view directory
set dirname [lindex [file split [pwd]] end]
# Ok, now go to the upper dir...
cd ..
# and try again with git top. If fails, it's not a submodule.
if { [catch {set top [exec git rev-parse --show-toplevel]} err] } {
puts stderr "Looxlike '$sub' is not a submodule directory"
puts stderr $err
exit 1
}
} else {
if { [catch {set top [exec git rev-parse --show-toplevel]} err] } {
puts stderr "Looxlike [pwd] is not a git repo directory"
puts stderr $err
exit 1
}
# Make sure the path is clean
set dirname [file join {*}[file split $dirname]]
}
# Don't change dir to this dir though. Read from the current dir.
set sublist [exec git ls-tree HEAD]
foreach l [split $sublist \n] {
lassign $l rights type hash name
if { $name == $dirname } {
puts $hash
exit 0
}
}
puts stderr "Note: '$dirname' not found in the tree list:\n$sublist"
exit 1