forked from hoelzro/useful-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-fg
More file actions
57 lines (40 loc) · 1.06 KB
/
git-fg
File metadata and controls
57 lines (40 loc) · 1.06 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
#!/home/rob/.mokudo/bin/perl6
use v6;
my $*BRANCH-VERIFIED = False;
sub resolve-git-job-reference(Int $target-refnum) returns Str {
my @lines = qq:x"git jobs".chomp.lines;
my Str $branch-name;
for @lines -> $line {
my ( $refnum, $name ) = $line.split;
if $refnum == $target-refnum {
return $name;
}
}
die "Unable to resolve $target-refnum to a branch name";
}
sub assert-branch-wip(Str $branch) {
return if $*BRANCH-VERIFIED;
my @lines = qq:x"git jobs".chomp.lines;
for @lines -> $line {
my ( $, $name ) = $line.split;
if $branch eq $name {
return;
}
}
die "Branch '$branch' wasn't backgrounded";
}
sub assert-worktree-clean() {
}
multi sub MAIN() {
MAIN(1)
}
multi sub MAIN(Int $branch-reference) {
my $*BRANCH-VERIFIED = True;
MAIN(resolve-git-job-reference($branch-reference))
}
multi sub MAIN(Str $branch) {
assert-branch-wip($branch);
assert-worktree-clean();
run('git', 'checkout', $branch);
run('git', 'reset', 'HEAD^');
}