Inheritance: NGit.Storage.File.FileRepository
Example #1
0
		public override void CopyConfigurationFrom (Repository other)
		{
			base.CopyConfigurationFrom (other);

			GitRepository r = (GitRepository)other;
			RootPath = r.RootPath;
			if (!RootPath.IsNullOrEmpty)
				RootRepository = new LocalGitRepository (RootPath);
		}
Example #2
0
		public GitRepository (FilePath path, string url)
		{
			RootPath = path;
			RootRepository = new LocalGitRepository (path.Combine (Constants.DOT_GIT));
			Url = url;
		}
Example #3
0
		public static LocalGitRepository Init (string targetLocalPath, string url, IProgressMonitor monitor)
		{
			InitCommand ci = new InitCommand ();
			ci.SetDirectory (targetLocalPath);
			ci.Call ();
			LocalGitRepository repo = new LocalGitRepository (Path.Combine (targetLocalPath, Constants.DOT_GIT));
			
			string branch = Constants.R_HEADS + "master";
			
			RefUpdate head = repo.UpdateRef (Constants.HEAD);
			head.DisableRefLog ();
			head.Link (branch);
			
			if (url != null) {
				RemoteConfig remoteConfig = new RemoteConfig (repo.GetConfig (), "origin");
				remoteConfig.AddURI (new URIish (url));
				
				string dst = Constants.R_REMOTES + remoteConfig.Name;
				RefSpec wcrs = new RefSpec();
				wcrs = wcrs.SetForceUpdate (true);
				wcrs = wcrs.SetSourceDestination (Constants.R_HEADS	+ "*", dst + "/*");
				
				remoteConfig.AddFetchRefSpec (wcrs);
				remoteConfig.Update (repo.GetConfig());
			}
	
			// we're setting up for a clone with a checkout
			repo.GetConfig().SetBoolean ("core", null, "bare", false);
	
			repo.GetConfig().Save();
			return repo;
		}
Example #4
0
		public GitRepository (FilePath path, string url)
		{
			this.path = path;
			Url = url;
			repo = new LocalGitRepository (path.Combine (Constants.DOT_GIT));
		}
Example #5
0
		public override Repository Publish (string serverPath, FilePath localPath, FilePath[] files, string message, IProgressMonitor monitor)
		{
			// Initialize the repository
			repo = GitUtil.Init (localPath, Url, monitor);
			path = localPath;
			
			// Add the project files
			ChangeSet cs = CreateChangeSet (localPath);
			NGit.Api.Git git = new NGit.Api.Git (repo);
			var cmd = git.Add ();
			foreach (FilePath fp in files) {
				cmd.AddFilepattern (ToGitPath (fp));
				cs.AddFile (fp);
			}
			cmd.Call ();
			
			// Create the initial commit
			cs.GlobalComment = message;
			Commit (cs, monitor);

			// Push to remote repo
			Push (monitor, "origin", "master");
			
			return this;
		}
Example #6
0
		public override void CopyConfigurationFrom (Repository other)
		{
			base.CopyConfigurationFrom (other);
			GitRepository r = (GitRepository)other;
			path = r.path;
			if (r.repo != null)
				repo = new LocalGitRepository (path);
		}
Example #7
0
		public override Repository Publish (string serverPath, FilePath localPath, FilePath[] files, string message, IProgressMonitor monitor)
		{
			// Initialize the repository
			repo = GitUtil.Init (localPath, Url, monitor);
			NGit.Api.Git git = new NGit.Api.Git (repo);
			try {
				var refs = git.Fetch ().Call ().GetAdvertisedRefs ();
				if (refs.Count > 0) {
					throw new UserException ("The remote repository already contains branches. MonoDevelop can only publish to an empty repository");
				}
			} catch {
				if (Directory.Exists (repo.Directory))
					Directory.Delete (repo.Directory, true);
				repo.Close ();
				repo = null;
				throw;
			}

			path = localPath;
			// Add the project files
			ChangeSet cs = CreateChangeSet (localPath);
			var cmd = git.Add ();
			foreach (FilePath fp in files) {
				cmd.AddFilepattern (ToGitPath (fp));
				cs.AddFile (fp);
			}
			cmd.Call ();
			
			// Create the initial commit
			cs.GlobalComment = message;
			Commit (cs, monitor);

			// Push to remote repo
			Push (monitor, "origin", "master");

			return this;
		}