From: Joseph Nuthalapati Date: Wed, 30 Dec 2020 06:20:53 +0000 (+0530) Subject: git-pull-all X-Git-Url: http://njoseph.me/gitweb/goutils.git/commitdiff_plain/ff524faff7ad56c73fc3108d4d6db2975a3b1bf5 git-pull-all Command to pull all the repositories under a given directory. --- ff524faff7ad56c73fc3108d4d6db2975a3b1bf5 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42eb124 --- /dev/null +++ b/.gitignore @@ -0,0 +1,128 @@ +# Created by https://www.toptal.com/developers/gitignore/api/intellij,go +# Edit at https://www.toptal.com/developers/gitignore?templates=intellij,go + +### Go ### +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +### Go Patch ### +/vendor/ +/Godeps/ + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# End of https://www.toptal.com/developers/gitignore/api/intellij,go diff --git a/README.md b/README.md new file mode 100644 index 0000000..5fe938d --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Go Utils + +Utilities written in Go language, mostly to make use of cheap concurrency using goroutines. + +## Usage + +Compile and put goutils binary somewhere on your PATH. + +## Utils + +### Git Pull All + +Command to pull all the repositories under a given directory. + +```shell script +cd dir/with/all/the/repos +goutils git-pull-all + +# Alias +goutils gpa +``` + +## Aliases + +```shell script +alias gpa="goutils git-pull-all" +``` diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d327ad2 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module njoseph.me/goutils + +go 1.15 + +require github.com/urfave/cli v1.22.5 diff --git a/main.go b/main.go new file mode 100644 index 0000000..b8f71d0 --- /dev/null +++ b/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "log" + "os" + + "github.com/urfave/cli" + "njoseph.me/goutils/utils" +) + +var app = cli.NewApp() + +func Info() { + app.Name = "Go Utils" + app.Usage = "goutils command" + app.Author = "Joseph Nuthalapati" + app.Version = "0.0.1" +} + +func Commands() { + app.Commands = []cli.Command{ + { + Name: "git-pull-all", + Aliases: []string{"gpa"}, + Action: func(c *cli.Context) { + utils.GitPullAll() + }, + }, + } +} + +func main() { + Info() + Commands() + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} diff --git a/utils/git_pull_all.go b/utils/git_pull_all.go new file mode 100644 index 0000000..f2bd685 --- /dev/null +++ b/utils/git_pull_all.go @@ -0,0 +1,41 @@ +package utils + +import ( + "io/ioutil" + "log" + "os" + "os/exec" + "sync" +) + +func GitPullAll() { + currentDirectory, err := os.Getwd() + if err != nil { + log.Fatal("Error when trying to get current directory!") + } else { + log.Println("Pulling all git repositories in the directory: ", currentDirectory, "...") + + files, err := ioutil.ReadDir("./") + if err != nil { + log.Fatal(err.Error()) + } + var wg sync.WaitGroup + + for _, f := range files { + if f.IsDir() { + wg.Add(1) + go doGitPull(&wg, f) + } + } + wg.Wait() + } +} + +func doGitPull(wg *sync.WaitGroup, dir os.FileInfo) { + defer wg.Done() + output, err := exec.Command("git", "-C", dir.Name(), "pull", "--rebase").Output() + if err != nil { + log.Println("Error pulling", dir.Name(), err.Error()) + } + log.Println("Pulling", dir.Name(), "\n", string(output)) +}