Skip to content

Commit

Permalink
add flag to download to force fetch files if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
autholykos committed Feb 21, 2020
1 parent a71d386 commit ced9c71
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 27 deletions.
77 changes: 52 additions & 25 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,11 @@ var downloadCmd = &cobra.Command{
Use: "download",
Short: "update your local repository with all changes performed remotely",
RunE: func(cmd *cobra.Command, args []string) error {
cfg := &Conf{}
if err := viper.Unmarshal(cfg); err != nil {
return err
}

projects := make([]string, 0)
for _, repo := range cfg.Repos {
projects = append(projects, repo.Name)
}

prompt := promptui.Select{
Label: "select which project you want to sync",
Items: projects,
}

i, _, err := prompt.Run()
ft, err := cmd.PersistentFlags().GetBool("fetch-tracks")
if err != nil {
return err
}

out, err := common.ExecCmd("git", "-C", cfg.Repos[i].Location, "pull", "origin", "master")
if err != nil {
return err
}

Print(out)
return nil
return pull(ft)
},
}

Expand All @@ -64,9 +42,58 @@ func init() {

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// downloadCmd.PersistentFlags().String("foo", "", "A help for foo")
downloadCmd.PersistentFlags().BoolP("fetch-tracks", "f", false, "force git-lfs to fetch the actual tracks instead of the git-lfs links")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// downloadCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

func pull(fetchTracks bool) error {
cfg := &Conf{}
if err := viper.Unmarshal(cfg); err != nil {
return err
}

repo, err := selectLocalRepo(cfg)
if err != nil {
return err
}

out, err := common.ExecCmd("git", "-C", repo, "pull", "origin", "master")
if err != nil {
return err
}

Print(out)

if fetchTracks {
out, err := common.ExecCmd("git", "-C", repo, "lfs", "pull")
if err != nil {
return err
}

Print(out)
}
return nil
}

func selectLocalRepo(cfg *Conf) (string, error) {

projects := make([]string, 0)
for _, repo := range cfg.Repos {
projects = append(projects, repo.Name)
}

prompt := promptui.Select{
Label: "select which project you want to sync",
Items: projects,
}

i, _, err := prompt.Run()
if err != nil {
return "", err
}

return cfg.Repos[i].Location, nil
}
4 changes: 2 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var installCmd = &cobra.Command{
if err := viper.Unmarshal(cfg); err != nil {
return err
}
remoteRepo, err := selectRepo(sharedDir, cfg)
remoteRepo, err := selectRemoteRepo(sharedDir, cfg)
if err != nil {
return err
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func execGit(localRepo string, args ...string) error {
return nil
}

func selectRepo(sharedDir string, conf *Conf) (string, error) {
func selectRemoteRepo(sharedDir string, conf *Conf) (string, error) {
projects := make([]string, 0)
files, err := ioutil.ReadDir(sharedDir)
if err != nil {
Expand Down

0 comments on commit ced9c71

Please sign in to comment.