-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-next
More file actions
executable file
·83 lines (64 loc) · 1.88 KB
/
git-next
File metadata and controls
executable file
·83 lines (64 loc) · 1.88 KB
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
#!/usr/bin/tclsh
lassign $argv point top
if { $point == "" || $point == "." } {
set point HEAD
}
if { $top == "" } {
set this [exec git rev-parse $point]
# Now extract the reflog information from this commit
# There can be multiple lines of it, if the commit belonged
# to multiple branches at a time.
set lines [exec git reflog show {--format=%H %gd} --all | grep $this]
if { $lines == "" } {
puts stderr "Can't extract current reflog, unknown where the top can be. Please specify toplevel."
exit 1
}
puts stderr "REFLOG:\n$lines"
set brdata ""
foreach l [split $lines \n] {
#puts stderr "Line: '$l'"
# Skip the first word, it's the searched hash-pointer.
set l [lindex $l 1]
# This is a reflog info. Let's extract each one.
set left [split $l "@"]
set br [lindex $left 0]
set ver [string range [lindex $left 1] 1 end-1]
if { $br == "HEAD" } {
puts stderr "(skipping HEAD)"
continue
}
dict set brdata $br $ver
}
puts stderr "COLLECTED: $brdata"
set branches [dict keys $brdata]
if { [llength $branches] != 1 } {
# Try to extract the current branch and select this one
set brl [exec git branch | grep {^*}]
set br [string range $brl 2 end]
if { [string index $br 0] == "(" } {
# detached.
puts -nonewline stderr "Can't extract the toplevel by branchname from reflog nor current branch."
if { $branches == "" } {
puts stderr " Can't find your branch name."
} else {
puts stderr " Please select one of:"
foreach b $branches {
puts stderr $b
}
}
exit 1
} else {
set top $br
}
} else {
set top [lindex $branches 0]
}
if { $top == "HEAD" } {
puts stderr "This is HEAD reflog, looxlike the reflog was wiped out. Please specify your branch."
exit 1
}
}
set list [exec git rev-list --ancestry-path $point..$top]
# Our child is at the bottom of the list
set last [lindex [split $list \n] end]
puts $last