久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

JGit有哪些常用的方法

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

為渝中等地區(qū)用戶(hù)提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及渝中網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、渝中網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專(zhuān)業(yè)、用心的態(tài)度為用戶(hù)提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶(hù)的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!

package ;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

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

public class GitService {

	private Git git;
	private CredentialsProvider credentialsProvider;
	private static String gitFile = ".git";
	private static String repoName = "repo/";

	GitService(Git git){
		this.git = git;
	}
	
	GitService(String repositoryUrl, String username, String pwd, String localRepo,String branchName) throws Exception{
		this.credentialsProvider = new UsernamePasswordCredentialsProvider(username,pwd);
		initRepo(credentialsProvider,repositoryUrl,localRepo,branchName);
	}

	public void initRepo(CredentialsProvider credentialsProvider,String repositoryUrl, String localRepo, String branchName) throws Exception{
//		if(StringUtils.isEmpty(repoDir)||StringUtils.isEmpty(localRepo)||StringUtils.isEmpty(branchName)){
//			//error
//			return;
//		}
//		File localDir = new File(localRepo);  
//		//init and clone the repo
//		if (!new File(repoDir + File.separator + gitFile).exists()) {  
//			Git.init().setDirectory(localDir).call();
//			Git.cloneRepository().setURI(repoDir).setBranch(branchName)
//			.setDirectory(new File(localRepo)).call();
//		}  
		createLocalRepo(localRepo);
		if (!new File(localRepo + gitFile).exists()) {  
			this.git = Git.cloneRepository().setCredentialsProvider(credentialsProvider).setURI(repositoryUrl).setBranch(branchName)
					.setDirectory(new File(localRepo)).call();
		}else{
			this.git = Git.open( new File(localRepo));
		}
	}
	
	private static void createLocalRepo(String repositoryDir){
		File file = new File(repositoryDir);
		if(!file.exists()){
			file.mkdirs();
		}
	}

	public void pullRepo(String branchName) throws Exception{
		git.pull().setRemoteBranchName(branchName).setCredentialsProvider(credentialsProvider).call();
	}

	public void resetLocalRepo(String repoDir, String localRepo, String branchName) throws Exception{
		if(StringUtils.isEmpty(repoDir)||StringUtils.isEmpty(localRepo)||StringUtils.isEmpty(branchName)){
			//error
			return;
		}
		File file = new File(localRepo);
		if(file.canWrite()&&file.exists()){
			file.delete();
		}
		file.mkdirs();
		initRepo(credentialsProvider,repoDir,localRepo,branchName);
	}

	public void pushRepo(List<String> files) throws Exception{
		if(!files.isEmpty()){
			AddCommand addCmd = git.add();  
			for (String file : files) {  
				addCmd.addFilepattern(file);  
			}  
			addCmd.call();
			git.commit().setMessage("Authomated push the code").call();
			git.push().setCredentialsProvider(credentialsProvider).call();
		}else{
			// no updates
		}
		String file = "repo/sourcTest.java";
//		git.add().addFilepattern(file).call();
		git.commit().setOnly(file).setMessage("Automated push the code");
		git.push().call();
	}
	
	public static void main(String[] args) throws Exception{
		String repoUrl = "";
		String user = "";
		String localRepoDir = ProjectUser.getPath(user)+repoName;
		String username = "";
		String pwd = "";
		String branchName = "";
		
//		Git git = JGitService.getGitByPwd(repoUrl, username, pwd, localRepoDir,branchName);
//		GitService service = new GitService(git);
//		service.initRepo(repoUrl,localRepoDir,branchName);
		
//		service.pullRepo(branchName);
		
//		List<String> files = new ArrayList<>();
//		files.add("repo/test/TestPush.java");
//		files.add(".+");
//		service.pushRepo(files);
		test();
	}
	
	public static void test() throws Exception{
		String repoUrl = "";
		String user = "";
		String localRepoDir = ProjectUser.getPath(user)+repoName;
		String username = "";
		String pwd = "";
		String branchName = "";
		CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username,
				pwd);
		
		Git git = JGitService.getGitByPwd(repoUrl, username, pwd, localRepoDir,branchName);
//		GitService service = new GitService(git);
		
//		DirCache index = git.add().addFilepattern("test/").call();
		AddCommand addCmd = git.add();
		addCmd.addFilepattern("sourcTest.java");
		DirCache index = addCmd.call();
		int count = index.getEntryCount();
		System.out.println("Updated count: "+count);
		git.commit().setMessage("Automated push the code").call();
		git.push().setCredentialsProvider(credentialsProvider).call();
		
		
	}
}

到此,關(guān)于“JGit有哪些常用的方法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

標(biāo)題名稱(chēng):JGit有哪些常用的方法
本文鏈接:http://sd-ha.com/article24/jiisje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航Google、電子商務(wù)網(wǎng)站排名、網(wǎng)站設(shè)計(jì)、定制開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)