Skip to content

Commit

Permalink
fixed cloning a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
scrouthtv committed Oct 10, 2021
1 parent ef5de56 commit fdc5bf4
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var (
targetBase string
createFoldersInTarget bool
cloneRoot bool
)

var (
Expand All @@ -28,14 +28,16 @@ type Task struct {
// and whether to recreate the root folders inside the target.
func Setup(base string, cloneFolders bool) {
targetBase = base
createFoldersInTarget = cloneFolders
cloneRoot = cloneFolders

sources = nil
pendingConflicts = nil
solvedConflicts = nil
folders = nil

addFolder(base)
if cloneFolders {
addFolder(base)
}

if flags.Current.Verbosity() >= flags.VerbDebug {
fmt.Println("create folders in target:", cloneFolders)
Expand Down Expand Up @@ -137,12 +139,12 @@ func AddFolder(folder string) {
return
}

if !createFoldersInTarget && filepath.Dir(folder) == "." {
if !cloneRoot && filepath.Dir(folder) == "." {
// don't recreate root folders
return
}

if !createFoldersInTarget {
if !cloneRoot {
folder = removeFirst(folder)
}

Expand All @@ -158,7 +160,7 @@ func addFolder(f string) {
}

func destFor(p *Path) string {
if createFoldersInTarget {
if cloneRoot {
return filepath.Join(targetBase, filepath.Base(p.Base), p.Sub)
} else {
return filepath.Join(targetBase, p.Sub)
Expand All @@ -180,9 +182,13 @@ func PrintTasks() {
filepath.Clean(destFor(&source)))
}

fmt.Println("Need to create these folders:")
for _, folder := range folders {
fmt.Printf(" - %s\n", folder)
if len(folders) == 0 {
fmt.Println("No folders to create.")
} else {
fmt.Println("Need to create these folders:")
for _, folder := range folders {
fmt.Printf(" - %s\n", folder)
}
}

lock.RUnlock()
Expand Down

0 comments on commit fdc5bf4

Please sign in to comment.