Compare commits
1 Commits
e3d5bb6a3e
...
c642efcf8c
Author | SHA1 | Date | |
---|---|---|---|
c642efcf8c |
@ -28,17 +28,17 @@ func gitCloneIgnoreErr(err error) bool {
|
|||||||
// Clone runs a git clone which accounts for different default branches.
|
// Clone runs a git clone which accounts for different default branches.
|
||||||
func Clone(dir, url string) error {
|
func Clone(dir, url string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancelCtx := context.WithCancel(ctx)
|
||||||
|
|
||||||
|
sigIntCh := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigIntCh, os.Interrupt)
|
||||||
|
defer func() {
|
||||||
|
signal.Stop(sigIntCh)
|
||||||
|
cancelCtx()
|
||||||
|
}()
|
||||||
|
|
||||||
errCh := make(chan error)
|
errCh := make(chan error)
|
||||||
|
|
||||||
c := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(c, os.Interrupt)
|
|
||||||
defer func() {
|
|
||||||
signal.Stop(c)
|
|
||||||
cancel()
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||||
log.Debugf("git clone: %s", url)
|
log.Debugf("git clone: %s", url)
|
||||||
@ -88,8 +88,8 @@ func Clone(dir, url string) error {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-c:
|
case <-sigIntCh:
|
||||||
cancel()
|
cancelCtx()
|
||||||
fmt.Println() // NOTE(d1): newline after ^C
|
fmt.Println() // NOTE(d1): newline after ^C
|
||||||
if err := os.RemoveAll(dir); err != nil {
|
if err := os.RemoveAll(dir); err != nil {
|
||||||
return fmt.Errorf("unable to clean up git clone of %s: %s", dir, err)
|
return fmt.Errorf("unable to clean up git clone of %s: %s", dir, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user