日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

JGit有哪些常用的方法

發(fā)布時(shí)間:2023/12/15 37 生活家
生活随笔 收集整理的這篇文章主要介紹了 JGit有哪些常用的方法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這篇文章主要介紹“JGit有哪些常用的方法”,在日常操作中,相信很多人在JGit有哪些常用的方法問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”JGit有哪些常用的方法”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

package;

importjava.io.File;
importjava.util.ArrayList;
importjava.util.List;

importorg.apache.commons.lang3.StringUtils;
importorg.eclipse.jgit.api.AddCommand;
importorg.eclipse.jgit.api.Git;
importorg.eclipse.jgit.diff.DiffEntry;
importorg.eclipse.jgit.diff.DiffEntry.ChangeType;
importorg.eclipse.jgit.dircache.DirCache;
importorg.eclipse.jgit.revwalk.RevCommit;
importorg.eclipse.jgit.transport.CredentialsProvider;
importorg.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
importorg.eclipse.jgit.treewalk.filter.PathFilterGroup;

publicclassGitService{

	privateGitgit;
	privateCredentialsProvidercredentialsProvider;
	privatestaticStringgitFile=".git";
	privatestaticStringrepoName="repo/";

	GitService(Gitgit){
		this.git=git;
	}
	
	GitService(StringrepositoryUrl,Stringusername,Stringpwd,StringlocalRepo,StringbranchName)throwsException{
		this.credentialsProvider=newUsernamePasswordCredentialsProvider(username,pwd);
		initRepo(credentialsProvider,repositoryUrl,localRepo,branchName);
	}

	publicvoidinitRepo(CredentialsProvidercredentialsProvider,StringrepositoryUrl,StringlocalRepo,StringbranchName)throwsException{
//		if(StringUtils.isEmpty(repoDir)||StringUtils.isEmpty(localRepo)||StringUtils.isEmpty(branchName)){
//			//error
//			return;
//		}
//		FilelocalDir=newFile(localRepo);
//		//initandclonetherepo
//		if(!newFile(repoDir+File.separator+gitFile).exists()){
//			Git.init().setDirectory(localDir).call();
//			Git.cloneRepository().setURI(repoDir).setBranch(branchName)
//			.setDirectory(newFile(localRepo)).call();
//		}
		createLocalRepo(localRepo);
		if(!newFile(localRepo+gitFile).exists()){
			this.git=Git.cloneRepository().setCredentialsProvider(credentialsProvider).setURI(repositoryUrl).setBranch(branchName)
					.setDirectory(newFile(localRepo)).call();
		}else{
			this.git=Git.open(newFile(localRepo));
		}
	}
	
	privatestaticvoidcreateLocalRepo(StringrepositoryDir){
		Filefile=newFile(repositoryDir);
		if(!file.exists()){
			file.mkdirs();
		}
	}

	publicvoidpullRepo(StringbranchName)throwsException{
		git.pull().setRemoteBranchName(branchName).setCredentialsProvider(credentialsProvider).call();
	}

	publicvoidresetLocalRepo(StringrepoDir,StringlocalRepo,StringbranchName)throwsException{
		if(StringUtils.isEmpty(repoDir)||StringUtils.isEmpty(localRepo)||StringUtils.isEmpty(branchName)){
			//error
			return;
		}
		Filefile=newFile(localRepo);
		if(file.canWrite()&&file.exists()){
			file.delete();
		}
		file.mkdirs();
		initRepo(credentialsProvider,repoDir,localRepo,branchName);
	}

	publicvoidpushRepo(List<String>files)throwsException{
		if(!files.isEmpty()){
			AddCommandaddCmd=git.add();
			for(Stringfile:files){
				addCmd.addFilepattern(file);
			}
			addCmd.call();
			git.commit().setMessage("Authomatedpushthecode").call();
			git.push().setCredentialsProvider(credentialsProvider).call();
		}else{
			//noupdates
		}
		Stringfile="repo/sourcTest.java";
//		git.add().addFilepattern(file).call();
		git.commit().setOnly(file).setMessage("Automatedpushthecode");
		git.push().call();
	}
	
	publicstaticvoidmain(String[]args)throwsException{
		StringrepoUrl="";
		Stringuser="";
		StringlocalRepoDir=ProjectUser.getPath(user)+repoName;
		Stringusername="";
		Stringpwd="";
		StringbranchName="";
		
//		Gitgit=JGitService.getGitByPwd(repoUrl,username,pwd,localRepoDir,branchName);
//		GitServiceservice=newGitService(git);
//		service.initRepo(repoUrl,localRepoDir,branchName);
		
//		service.pullRepo(branchName);
		
//		List<String>files=newArrayList<>();
//		files.add("repo/test/TestPush.java");
//		files.add(".+");
//		service.pushRepo(files);
		test();
	}
	
	publicstaticvoidtest()throwsException{
		StringrepoUrl="";
		Stringuser="";
		StringlocalRepoDir=ProjectUser.getPath(user)+repoName;
		Stringusername="";
		Stringpwd="";
		StringbranchName="";
		CredentialsProvidercredentialsProvider=newUsernamePasswordCredentialsProvider(username,
				pwd);
		
		Gitgit=JGitService.getGitByPwd(repoUrl,username,pwd,localRepoDir,branchName);
//		GitServiceservice=newGitService(git);
		
//		DirCacheindex=git.add().addFilepattern("test/").call();
		AddCommandaddCmd=git.add();
		addCmd.addFilepattern("sourcTest.java");
		DirCacheindex=addCmd.call();
		intcount=index.getEntryCount();
		System.out.println("Updatedcount:"+count);
		git.commit().setMessage("Automatedpushthecode").call();
		git.push().setCredentialsProvider(credentialsProvider).call();
		
		
	}
}

總結(jié)

以上是生活随笔為你收集整理的JGit有哪些常用的方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。