From 6a64c741a4a43548c12a698379beb79236dc60fe Mon Sep 17 00:00:00 2001 From: Arbaaz Laskar Date: Wed, 5 Jul 2023 22:58:02 +0530 Subject: [PATCH] =?UTF-8?q?Bump=20version:=200.5.0=20=E2=86=92=200.5.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixed the issue where the pull command were not pulling the changes to the branch --- .git-utils-bump.cfg | 2 +- README.md | 2 +- cmd/pull.go | 26 ++++++++++++++------------ cmd/root.go | 2 +- utils/update_checker.go | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.git-utils-bump.cfg b/.git-utils-bump.cfg index bd891bd..460393a 100644 --- a/.git-utils-bump.cfg +++ b/.git-utils-bump.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.5.0 +current_version = 0.5.1 commit = True tag = False tag_format = v{tag} diff --git a/README.md b/README.md index 9ff3b92..da39c76 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ go install github.com/arzkar/git-utils@latest ``` > git-utils -git-utils v0.5.0 +git-utils v0.5.1 Copyright (c) Arbaaz Laskar A CLI for performing various operations on git repositories diff --git a/cmd/pull.go b/cmd/pull.go index 354393d..2523931 100644 --- a/cmd/pull.go +++ b/cmd/pull.go @@ -103,7 +103,8 @@ func pullRepository(path string, pull string, dryRun bool) error { } else { branches := strings.Split(pull, ",") for _, branch := range branches { - err := pullBranch(path, branch, dryRun) + localBranch := strings.TrimSpace(strings.TrimPrefix(branch, "origin/")) + err := pullBranch(path, localBranch, branch, dryRun) if err != nil { return err } @@ -122,7 +123,8 @@ func pullAllBranches(path string, dryRun bool) error { branches := strings.Split(strings.TrimSpace(string(output)), "\n") for _, branch := range branches { - err := pullBranch(path, branch, dryRun) + localBranch := strings.TrimSpace(strings.TrimPrefix(branch, "origin/")) + err := pullBranch(path, localBranch, branch, dryRun) if err != nil { return err } @@ -131,29 +133,29 @@ func pullAllBranches(path string, dryRun bool) error { return nil } -func pullBranch(path string, branch string, dryRun bool) error { - fmt.Printf("Pulling branch '%s' in repository '%s'\n", branch, path) - execDryRun(dryRun, path, branch) +func pullBranch(path string, localBranch string, remoteBranch string, dryRun bool) error { + fmt.Printf("Pulling branch '%s' in repository '%s'\n", localBranch, path) + execDryRun(dryRun, path, localBranch) // Show the changes made by the pull operation - cmd := exec.Command("git", "-C", path, "diff", "--stat", branch+"..origin/"+branch) + cmd := exec.Command("git", "-C", path, "diff", "--stat", localBranch+"..origin/"+remoteBranch) output, err := cmd.CombinedOutput() if err != nil { - return fmt.Errorf("failed to get changes made by pull for branch '%s' in repository '%s': %w\n%s", branch, path, err, string(output)) + return fmt.Errorf("failed to get changes made by pull for branch '%s' in repository '%s': %w\n%s", localBranch, path, err, string(output)) } - if len(output) > 0 { - fmt.Println("Changes made by pull:") + fmt.Println("Diff: " + localBranch + "..origin/" + remoteBranch) colorizedOutput := utils.ColorizeDiffStat(string(output)) fmt.Println(colorizedOutput) - cmd = exec.Command("git", "-C", path, "pull") + cmd = exec.Command("git", "-C", path, "pull", "origin", remoteBranch+":"+localBranch) output, err = cmd.CombinedOutput() + // println(string(output)) if err != nil { - return fmt.Errorf("failed to pull branch '%s' in repository '%s': %w\n%s", branch, path, err, string(output)) + return fmt.Errorf("failed to pull branch '%s' in repository '%s': %w\n%s", localBranch, path, err, string(output)) } - fmt.Printf(color.GreenString("Successfully pulled branch '%s' in repository '%s'\n\n", branch, path)) + fmt.Printf(color.GreenString("Successfully pulled branch '%s' in repository '%s'\n\n", localBranch, path)) } else { fmt.Println(color.GreenString("No changes made by pull\n")) } diff --git a/cmd/root.go b/cmd/root.go index 37c14eb..98bb5ec 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -26,7 +26,7 @@ import ( var rootCmd = &cobra.Command{ Use: "git-utils", Short: "A CLI for performing various operations on git repositories", - Long: `git-utils v0.5.0 + Long: `git-utils v0.5.1 Copyright (c) Arbaaz Laskar A CLI for performing various operations on git repositories diff --git a/utils/update_checker.go b/utils/update_checker.go index 3e07ec3..8c61d20 100644 --- a/utils/update_checker.go +++ b/utils/update_checker.go @@ -31,7 +31,7 @@ const ( repoOwner = "arzkar" repoName = "git-utils" releasesAPI = "https://api.github.com/repos/%s/%s/releases/latest" - currentVersion = "v0.5.0" + currentVersion = "v0.5.1" configFile = "config.json" updateInterval = 24 * time.Hour )