]> source.dussan.org Git - gitea.git/commitdiff
Fix empty checkout bug (#3419)
authorEthan Koenig <ethantkoenig@gmail.com>
Sun, 28 Jan 2018 11:27:42 +0000 (04:27 -0700)
committerLauris BH <lauris@nix.lv>
Sun, 28 Jan 2018 11:27:42 +0000 (13:27 +0200)
models/repo.go

index 59d2336781d609bb02fef69c376ecea7f4d7599b..42141985673ee6051acab2212d3d3e21eb63a3f3 100644 (file)
@@ -774,17 +774,17 @@ func UpdateLocalCopyBranch(repoPath, localPath, branch string) error {
                        return fmt.Errorf("git clone %s: %v", branch, err)
                }
        } else {
-               if err := git.Checkout(localPath, git.CheckoutOptions{
-                       Branch: branch,
-               }); err != nil {
-                       return fmt.Errorf("git checkout %s: %v", branch, err)
-               }
-
                _, err := git.NewCommand("fetch", "origin").RunInDir(localPath)
                if err != nil {
                        return fmt.Errorf("git fetch origin: %v", err)
                }
                if len(branch) > 0 {
+                       if err := git.Checkout(localPath, git.CheckoutOptions{
+                               Branch: branch,
+                       }); err != nil {
+                               return fmt.Errorf("git checkout %s: %v", branch, err)
+                       }
+
                        if err := git.ResetHEAD(localPath, true, "origin/"+branch); err != nil {
                                return fmt.Errorf("git reset --hard origin/%s: %v", branch, err)
                        }