Commits

Christian Specht committed 087f1eb

always authenticate when pulling repositories

Comments (0)

Files changed (2)

src/BitbucketBackup/Program.cs

                 var repoUri = new Uri(baseUri, repo.RepoName);
                 string repoPath = Path.Combine(config.BackupFolder, repo.RepoName);                
 
-                var updater = new RepositoryUpdater(repoUri, repoPath);
+                var updater = new RepositoryUpdater(repoUri, repoPath, config);
                 updater.Update();
 
                 if (repo.HasWiki)
                     var wikiUri = new Uri(baseUri, repo.RepoName + "/wiki");
                     string wikiPath = Path.Combine(config.BackupFolder, repo.RepoName + "-wiki");
 
-                    var wikiUpdater = new RepositoryUpdater(wikiUri, wikiPath);
+                    var wikiUpdater = new RepositoryUpdater(wikiUri, wikiPath, config);
                     wikiUpdater.Update();
                 }
             }

src/BitbucketBackup/RepositoryUpdater.cs

         private Uri repouri;
 
         /// <summary>
+        /// URI to remote repository, but with authentication
+        /// </summary>
+        private Uri repouriwithauth;
+
+        /// <summary>
         /// local destination for repository clone
         /// </summary>
         private string localfolder;
 
         /// <summary>
+        /// configuration settings
+        /// </summary>
+        private Config config;
+
+        /// <summary>
         /// Creates a new RepositoryUpdater instance
         /// </summary>
         /// <param name="repoUri">URI to remote repository</param>
         /// <param name="destinationFolder">local destination for repository clone</param>
-        public RepositoryUpdater(Uri repoUri, string localFolder)
+        /// <param name="config">configuration settings</param>
+        public RepositoryUpdater(Uri repoUri, string localFolder, Config config)
         {
             this.repouri = repoUri;
             this.localfolder = localFolder;
+            this.config = config;
+
+            string uriWithAuth = repoUri.ToString().Replace("://", string.Format("://{0}:{1}@", config.UserName, config.PassWord));
+            this.repouriwithauth = new Uri(uriWithAuth);
         }
 
         /// <summary>
             }
 
             Console.WriteLine(Resources.Pulling, this.repouri);
-            repo.Pull(this.repouri.ToString(), new PullCommand().WithUpdate(false));
+            repo.Pull(this.repouriwithauth.ToString(), new PullCommand().WithUpdate(false));
         }
     }
 }