项目:incubator-netbeans
文件:PullCommand.java
private String findRemoteBranchName () throws GitException {
Ref ref = null;
try {
ref = getRepository().getRef(branchToMerge);
} catch (IOException ex) {
throw new GitException(ex);
}
if (ref != null) {
for (String s : refSpecs) {
RefSpec spec = new RefSpec(s);
if (spec.matchDestination(ref)) {
spec = spec.expandFromDestination(ref);
String refName = spec.getSource();
if (refName.startsWith(Constants.R_HEADS)) {
return refName.substring(Constants.R_HEADS.length());
}
}
}
}
return branchToMerge;
}
项目:pdi-git-plugin
文件:UIGit.java
@Override
public void revertPath( String path ) {
try {
// Delete added files
Status status = git.status().addpath( path ).call();
if ( status.getUntracked().size() != 0 || status.getAdded().size() != 0 ) {
resetPath( path );
org.apache.commons.io.FileUtils.deleteQuietly( new File( directory,path ) );
}
/*
* This is a work-around to discard changes of conflicting files
* Git CLI `git checkout -- conflicted.txt` discards the changes,but jgit does not
*/
git.add().addFilepattern( path ).call();
git.checkout().setStartPoint( Constants.HEAD ).addpath( path ).call();
org.apache.commons.io.FileUtils.deleteQuietly( new File( directory,path + ".ours" ) );
org.apache.commons.io.FileUtils.deleteQuietly( new File( directory,path + ".theirs" ) );
} catch ( Exception e ) {
showMessageBox( BaseMessages.getString( PKG,"Dialog.Error" ),e.getMessage() );
}
}
项目:incubator-netbeans
文件:RebaseCommand.java
private GitRebaseResult createResult (RebaseResult res) {
String currHead;
Repository repository = getRepository();
File workTree = repository.getWorkTree();
try {
currHead = repository.resolve(Constants.HEAD).name();
} catch (IOException ex) {
currHead = Constants.HEAD;
}
List<File> conflicts;
if (res.getStatus() == RebaseResult.Status.STOPPED) {
conflicts = getConflicts(res.getCurrentCommit());
} else {
conflicts = Collections.<File>emptyList();
}
return getClassFactory().createRebaseResult(res,conflicts,getFailures(res),currHead);
}
项目:incubator-netbeans
文件:GitTransportUpdate.java
private static String stripRefs (String refName) {
if (refName == null) {
} else if (refName.startsWith(Constants.R_HEADS)) {
refName = refName.substring(Constants.R_HEADS.length());
} else if (refName.startsWith(Constants.R_TAGS)) {
refName = refName.substring(Constants.R_TAGS.length());
} else if (refName.startsWith(Constants.R_REMOTES)) {
refName = refName.substring(Constants.R_REMOTES.length());
} else if (refName.startsWith(Constants.R_REFS)) {
refName = refName.substring(Constants.R_REFS.length());
} else {
throw new IllegalArgumentException("UnkNown refName: " + refName);
}
return refName;
}
项目:incubator-netbeans
文件:GitTag.java
private GitObjectType getType (RevObject object) {
GitObjectType objType = GitObjectType.UNKNowN;
if (object != null) {
switch (object.getType()) {
case Constants.OBJ_COMMIT:
objType = GitObjectType.COMMIT;
break;
case Constants.OBJ_BLOB:
objType = GitObjectType.BLOB;
break;
case Constants.OBJ_TAG:
objType = GitObjectType.TAG;
break;
case Constants.OBJ_TREE:
objType = GitObjectType.TREE;
break;
}
}
return objType;
}
项目:incubator-netbeans
文件:GitClient.java
/**
* Exports uncommitted changes in files under given roots to the given output stream
* @param roots the diff will be exported only for modified files under these roots,can be empty to export all modifications in the whole working tree
* @param mode defines the compared trees
* @param out output stream the diff will be printed to
* @param monitor progress monitor
* @throws GitException an unexpected error occurs
*/
public void exportDiff (File[] roots,DiffMode mode,OutputStream out,ProgressMonitor monitor) throws GitException {
switch (mode) {
case HEAD_VS_INDEX:
exportDiff(roots,Constants.HEAD,INDEX,out,monitor);
break;
case HEAD_VS_WORKINGTREE:
exportDiff(roots,WORKING_TREE,monitor);
break;
case INDEX_VS_WORKINGTREE:
exportDiff(roots,monitor);
break;
default:
throw new IllegalArgumentException("UnkNown diff mode: " + mode);
}
}
public void testIgnoreFolderIgnoredEqualPath () throws Exception {
File f = new File(new File(new File(workdir,"sf1"),"sf2"),"folder");
f.mkdirs();
File gitIgnore = new File(workdir,Constants.DOT_GIT_IGnorE);
write(gitIgnore,"#ignoreFile\n/sf1/sf2/folder/");
File[] ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("#ignoreFile\n/sf1/sf2/folder/",read(gitIgnore));
assertEquals(0,ignores.length);
write(gitIgnore,"#ignoreFile\n/sf1/sf2/folder");
ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("#ignoreFile\n/sf1/sf2/folder",ignores.length);
}
public void testIgnoreFolderIgnoredPartialEqualPath () throws Exception {
File f = new File(new File(new File(workdir,"folder");
f.mkdirs();
new File(f,"file").createNewFile();
File gitIgnore = new File(workdir,"#ignoreFile\nfolder");
File[] ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("#ignoreFile\nfolder","#ignoreFile\nfolder/");
ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("#ignoreFile\nfolder/",ignores.length);
}
public void testIgnoreRemoveNegation () throws Exception {
File f = new File(new File(new File(workdir,"file");
f.getParentFile().mkdirs();
f.createNewFile();
File gitIgnore = new File(workdir,"#ignoreFile\n/sf1/sf2/file\n!/sf1/sf2/file");
File[] ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("#ignoreFile\n/sf1/sf2/file",read(gitIgnore));
assertEquals(Arrays.asList(gitIgnore),Arrays.asList(ignores));
write(gitIgnore,"");
File ignore2 = new File(f.getParentFile().getParentFile(),Constants.DOT_GIT_IGnorE);
write(ignore2,"!sf2/file");
ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("/sf1/sf2/file",read(gitIgnore));
assertEquals("",read(ignore2));
assertEquals(Arrays.asList(ignore2,gitIgnore),Arrays.asList(ignores));
}
public void testIgnoreFolderNoNegationRemoval () throws Exception {
File f = new File(new File(new File(workdir,"#ignoreFile\n/sf1/sf2/folder\n!folder");
File[] ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("#ignoreFile\n/sf1/sf2/folder\n!folder\n/sf1/sf2/folder/","#ignoreFile\n/sf1/sf2/folder\n!/sf1/sf2/folder");
ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("#ignoreFile\n/sf1/sf2/folder\n!/sf1/sf2/folder\n/sf1/sf2/folder/",Arrays.asList(ignores));
}
项目:incubator-netbeans
文件:CatTest.java
public void testCatRemoved () throws Exception {
File f = new File(workdir,"removed");
copyFile(getGoldenFile(),f);
assertFile(getGoldenFile(),f);
add(f);
commit(f);
GitClient client = getClient(workdir);
String revision = new Git(repository).log().call().iterator().next().getId().getName();
// remove and commit
client.remove(new File[] { f },false,NULL_PROGRESS_MONITOR);
commit(f);
assertTrue(client.catFile(f,revision,new FileOutputStream(f),NULL_PROGRESS_MONITOR));
assertFile(f,getGoldenFile());
assertFalse(client.catFile(f,NULL_PROGRESS_MONITOR));
}
public void testIgnoreRemoveNegation_nestedIgnoreFile () throws Exception {
File f = new File(new File(new File(workdir,"file");
f.getParentFile().mkdirs();
f.createNewFile();
File gitIgnore = new File(f.getParentFile().getParentFile(),"#ignoreFile\n/sf2/file\n!/sf2/file");
File[] ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("#ignoreFile\n/sf2/file",read(gitIgnore));
assertFalse(new File(workdir,Constants.DOT_GIT_IGnorE).exists());
assertEquals(Arrays.asList(gitIgnore),"sf2/file\n!sf2/file");
ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("sf2/file","#ignoreFile\nsf2/f*\n!/sf2/file");
ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("#ignoreFile\nsf2/f*",Arrays.asList(ignores));
}
public void testIgnoreFolderRemoveNegation_nestedIgnoreFile () throws Exception {
File f = new File(new File(new File(workdir,"folder");
f.mkdirs();
File gitIgnore = new File(f.getParentFile().getParentFile(),"#ignoreFile\n/sf2/folder/\n!/sf2/folder/");
File[] ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("#ignoreFile\n/sf2/folder/","#ignoreFile\nsf2/f*\n!/sf2/folder/");
ignores = getClient(workdir).ignore(new File[] { f },Arrays.asList(ignores));
}
public void testIgnoreFileWithBracket () throws Exception {
File f = new File(workdir,"fi[le");
f.createNewFile();
File gitIgnore = new File(workdir,Constants.DOT_GIT_IGnorE);
File[] ignores = getClient(workdir).ignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertEquals("/fi[[]le","/fi[[]le");
GitStatus st = getClient(workdir).getStatus(new File[] { f },NULL_PROGRESS_MONITOR).get(f);
assertEquals(Status.STATUS_IGnorED,st.getStatusIndexWC());
ignores = getClient(workdir).ignore(new File[] { f },"/fi\\[le");
// jgit seems to incorrectly handle escaped wildcards
st = getClient(workdir).getStatus(new File[] { f },NULL_PROGRESS_MONITOR);
assertEquals("/fi\\[le",ignores.length);
}
public void testUnignoreFolderWithNegation () throws Exception {
File f = new File(new File(new File(workdir,"/sf1/sf2/folder/\n!/sf1/sf2/folder/");
File[] ignores = getClient(workdir).unignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("!/sf1/sf2/folder/","/sf1/sf2/folder\n!/sf1/sf2/folder/");
ignores = getClient(workdir).unignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertTrue(gitIgnore.exists());
assertEquals("/sf1/sf2/folder\n!/sf1/sf2/folder/","!/sf1/sf2/folder/\n/sf1/sf2/folder/");
ignores = getClient(workdir).unignore(new File[] { f },Arrays.asList(ignores));
}
项目:incubator-netbeans
文件:BranchTest.java
public void testListBranches_Issue213538 () throws Exception {
GitClient client = getClient(workdir);
File f = new File(workdir,"f");
write(f,"init");
client.add(new File[] { f },NULL_PROGRESS_MONITOR);
client.commit(new File[] { f },"init commit",null,NULL_PROGRESS_MONITOR);
// cannot end with a RuntimeException
File configFile = new File(Utils.getMetadataFolder(workdir),Constants.CONfig);
String config = read(configFile);
config += "\n\tbla:\n";
write(configFile,config);
Thread.sleep(1100);
try {
client.getBranches(false,NULL_PROGRESS_MONITOR);
} catch (GitException ex) {
assertEquals("It seems the config file for repository at [" + workdir + "] is corrupted.\nEnsure it's valid.",ex.getMessage());
}
}
项目:pdi-git-plugin
文件:UIGit.java
private boolean mergeBranch( String value,String mergeStrategy ) {
try {
ObjectId obj = git.getRepository().resolve( value );
MergeResult result = git.merge()
.include( obj )
.setStrategy( MergeStrategy.get( mergeStrategy ) )
.call();
if ( result.getMergeStatus().isSuccessful() ) {
showMessageBox( BaseMessages.getString( PKG,"Dialog.Success" ),BaseMessages.getString( PKG,"Dialog.Success" ) );
return true;
} else {
showMessageBox( BaseMessages.getString( PKG,result.getMergeStatus().toString() );
if ( result.getMergeStatus() == MergeStatus.CONFLICTING ) {
result.getConflicts().keySet().forEach( path -> {
checkout( path,".ours" );
checkout( path,getExpandedname( value,IVCS.TYPE_BRANCH ),".theirs" );
} );
return true;
}
}
} catch ( Exception e ) {
showMessageBox( BaseMessages.getString( PKG,e.getMessage() );
}
return false;
}
项目:incubator-netbeans
文件:CheckoutTest.java
private void checkJGitFix (String branch,File file) throws Exception {
ObjectId headTree = null;
try {
headTree = Utils.findCommit(repository,Constants.HEAD).getTree();
} catch (GitException.MissingObjectException ex) { }
DirCache cache = repository.lockDirCache();
RevCommit commit;
commit = Utils.findCommit(repository,branch);
DirCacheCheckout dco = new DirCacheCheckout(repository,headTree,cache,commit.getTree());
dco.setFailOnConflict(false);
dco.checkout();
if (file.exists()) {
// and do not forget to remove WA in checkout command when JGit is fixed.
fail("hey,JGit is fixed,why don't you fix me as well?");
}
cache.unlock();
}
项目:incubator-netbeans
文件:CompareCommitTest.java
public void testCompareRevertModification () throws Exception {
File file = new File(workdir,"file");
File[] files = new File[] { file };
write(file,"init\n");
add(files);
commit(files);
GitClient client = getClient(workdir);
String revision1 = client.getBranches(false,NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId();
write(file,"modification\n");
add(files);
GitRevisionInfo revision2 = client.commit(files,"my commit message",NULL_PROGRESS_MONITOR);
write(file,"init\n");
add(files);
GitRevisionInfo revision3 = client.commit(files,"my commit 3 message",NULL_PROGRESS_MONITOR);
Map<File,GitRevisionInfo.GitFileInfo> statuses = client.getStatus(files,revision1,NULL_PROGRESS_MONITOR);
assertTrue(statuses.isEmpty());
}
项目:gitplex-mit
文件:Project.java
@Nullable
public String getDefaultBranch() {
if (defaultBranchOptional == null) {
try {
Ref headRef = getRepository().findRef("HEAD");
if (headRef != null
&& headRef.isSymbolic()
&& headRef.getTarget().getName().startsWith(Constants.R_HEADS)
&& headRef.getobjectId() != null) {
defaultBranchOptional = Optional.of(Repository.shortenRefName(headRef.getTarget().getName()));
} else {
defaultBranchOptional = Optional.absent();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return defaultBranchOptional.orNull();
}
项目:incubator-netbeans
文件:FetchTest.java
@Override
protected void setUp() throws Exception {
super.setUp();
workdir = getWorkingDirectory();
repository = getRepository(getLocalgitRepository());
otherWT = new File(workdir.getParentFile(),"repo2");
GitClient client = getClient(otherWT);
client.init(NULL_PROGRESS_MONITOR);
f = new File(otherWT,NULL_PROGRESS_MONITOR);
masterInfo = client.commit(new File[] { f },NULL_PROGRESS_MONITOR);
branch = client.createBranch(BRANCH_NAME,Constants.MASTER,NULL_PROGRESS_MONITOR);
RemoteConfig cfg = new RemoteConfig(repository.getConfig(),"origin");
cfg.addURI(new URIish(otherWT.toURI().toURL().toString()));
cfg.update(repository.getConfig());
repository.getConfig().save();
}
项目:incubator-netbeans
文件:AddTest.java
private void assertDirCacheEntryModified (Collection<File> files) throws IOException {
DirCache cache = repository.lockDirCache();
for (File f : files) {
String relativePath = Utils.getRelativePath(workdir,f);
DirCacheEntry e = cache.getEntry(relativePath);
assertNotNull(e);
assertEquals(relativePath,e.getPathString());
InputStream in = new FileInputStream(f);
try {
assertNotSame(e.getobjectId(),repository.newObjectInserter().idFor(Constants.OBJ_BLOB,f.length(),in));
} finally {
in.close();
}
}
cache.unlock();
}
public void testUnignoreFileInRoot () throws Exception {
File f = new File(workdir,"file");
f.createNewFile();
File gitIgnore = new File(workdir,Constants.DOT_GIT_IGnorE);
File[] ignores = getClient(workdir).unignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertFalse(gitIgnore.exists());
assertEquals(0,"/file");
ignores = getClient(workdir).unignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertEquals("","f\nf2\n/file\nf3\nf4");
ignores = getClient(workdir).unignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertEquals("f\nf2\nf3\nf4",Arrays.asList(ignores));
}
/**
*
* @param datarepo
* @param tree
* @param conn
* @param clmnTree
* @return
* @throws sqlException
* @throws IOException
*/
public static ObjectId dataTreeCommit(Repository datarepo,TreeFormatter tree,Connection conn,Boolean clmnTree) throws sqlException,IOException {
DatabaseMetaData dbmd = conn.getMetaData();
// ObjectJson dbmdJson = new ObjectJson();
String mapString = MetaDbInfo(dbmd);
// Build Db_Info object,general info about Database
ObjectInserter objectInserter = datarepo.newObjectInserter();
ObjectId blobId = objectInserter.insert(Constants.OBJ_BLOB,mapString.getBytes());
objectInserter.flush();
tree.append("DATABASE",FileMode.REGULAR_FILE,blobId);
// Continue building Database Tree
Utils.putTableMeta(datarepo,conn,dbmd,objectInserter,tree,clmnTree);
ObjectId treeId = objectInserter.insert(tree);
objectInserter.flush();
System.out.println("Tree ID: " + treeId.getName());
return treeId;
}
public void testUnignoreFolderInRoot () throws Exception {
File f = new File(workdir,"/folder/");
ignores = getClient(workdir).unignore(new File[] { f },"/folder");
ignores = getClient(workdir).unignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertEquals("/folder\n!/folder/",Arrays.asList(ignores));
}
public void testUnignoreFileInSubfolder () throws Exception {
File f = new File(new File(new File(workdir,"/sf1/sf2/file");
ignores = getClient(workdir).unignore(new File[] { f },"/sf1/sf2/file/");
ignores = getClient(workdir).unignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertEquals("/sf1/sf2/file/",ignores.length);
}
public void testUnignoreFolderInSubfolder () throws Exception {
File f = new File(new File(new File(workdir,"sf1/sf2/folder/");
ignores = getClient(workdir).unignore(new File[] { f },"/sf1/sf2/folder");
ignores = getClient(workdir).unignore(new File[] { f },NULL_PROGRESS_MONITOR);
assertEquals("/sf1/sf2/folder\n!/sf1/sf2/folder/",Arrays.asList(ignores));
}
项目:incubator-netbeans
文件:StatusCommand.java
@Override
protected String getCommandDescription () {
StringBuilder sb = new StringBuilder("git "); //NOI18N
if (Constants.HEAD.equals(revision)) {
sb.append("status"); //NOI18N
} else {
sb.append("diff --raw"); //NOI18N
}
for (File root : roots) {
sb.append(" ").append(root.getAbsolutePath());
}
return sb.toString();
}
项目:pdi-git-plugin
文件:GitControllerTest.java
@Test
public void testVisualDiff() throws Exception {
XulMessageBox message = spy( new XulMessageBoxMock( XulDialogCallback.Status.ACCEPT ) );
when( document.createElement( MESSAGEBox ) ).thenReturn( message );
UIFile file = new UIFile( "test.txt",ChangeType.MODIFY,true );
doReturn( Collections.singletonList( file ) ).when( controller ).getSelectedChangedFiles();
controller.visualdiff();
verify( message ).setTitle( BaseMessages.getString( PKG,"Dialog.Error" ) );
// .ktr
file = new UIFile( "test.ktr",true );
doReturn( Collections.singletonList( file ) ).when( controller ).getSelectedChangedFiles();
doReturn( new FileInputStream( new File( "src/test/resources/r1.ktr" ) ) ).when( uiGit ).open( "test.ktr",Constants.HEAD );
doReturn( new FileInputStream( new File( "src/test/resources/r2.ktr" ) ) ).when( uiGit ).open( "test.ktr",IVCS.WORKINGTREE );
controller.visualdiff();
verify( uiGit ).open( "test.ktr",Constants.HEAD );
verify( uiGit ).open( "test.ktr",IVCS.WORKINGTREE );
verify( controller ).loadMainPerspective();
// conflicted ktr
file = new UIFile( "test.kjb.ours",ChangeType.ADD,false );
File dir = File.createTempFile( "git_test_","_controller" );
dir.delete();
dir.mkdir();
File ours = new File( dir.getPath(),"test.kjb.ours" );
File theirs = new File( dir.getPath(),"test.kjb.theirs" );
FileUtils.copyFile( new File( "src/test/resources/r1.kjb" ),ours );
FileUtils.copyFile( new File( "src/test/resources/r2.kjb" ),theirs );
doReturn( dir.getPath() ).when( uiGit ).getDirectory();
doReturn( Collections.singletonList( file ) ).when( controller ).getSelectedChangedFiles();
doReturn( new FileInputStream( ours ) ).when( uiGit ).open( "test.kjb.ours",IVCS.WORKINGTREE );
doReturn( new FileInputStream( theirs ) ).when( uiGit ).open( "test.kjb.theirs",IVCS.WORKINGTREE );
controller.visualdiff();
FileUtils.deleteDirectory( dir );
verify( uiGit ).open( "test.kjb.ours",IVCS.WORKINGTREE );
verify( uiGit ).open( "test.kjb.theirs",IVCS.WORKINGTREE );
verify( controller,times( 2 ) ).loadMainPerspective();
}
项目:incubator-netbeans
文件:CherryPickCommand.java
private GitRevisionInfo getCurrentHead () {
GitRevisionInfo currHead;
Repository repository = getRepository();
try {
currHead = getClassFactory().createRevisionInfo(Utils.findCommit(repository,Constants.HEAD),repository);
} catch (GitException ex) {
currHead = null;
}
return currHead;
}
项目:incubator-netbeans
文件:CheckoutRevisionCommand.java
private void cacheContents (List<String> conflicts) throws IOException {
File workTree = getRepository().getWorkTree();
ObjectInserter inserter = getRepository().newObjectInserter();
WorkingTreeOptions opt = getRepository().getConfig().get(WorkingTreeOptions.KEY);
boolean autocrlf = opt.getAutoCRLF() != CoreConfig.AutoCRLF.FALSE;
try {
for (String path : conflicts) {
File f = new File(workTree,path);
Path p = null;
try {
p = f.toPath();
} catch (InvalidpathException ex) {
Logger.getLogger(CheckoutRevisionCommand.class.getName()).log(Level.FINE,ex);
}
if (p != null && Files.isSymbolicLink(p)) {
Path link = Utils.getLinkPath(p);
cachedContents.put(path,inserter.insert(Constants.OBJ_BLOB,Constants.encode(link.toString())));
} else if (f.isFile()) {
long sz = f.length();
try (FileInputStream in = new FileInputStream(f)) {
if (autocrlf) {
ByteBuffer buf = IO.readWholeStream(in,(int) sz);
cachedContents.put(path,buf.array(),buf.position(),buf.limit() - buf.position()));
} else {
cachedContents.put(path,sz,in));
}
}
}
}
inserter.flush();
} finally {
inserter.release();
}
}
项目:gerrit-plugin
文件:AbstractGerritSCMSource.java
/** {@inheritDoc} */
@NonNull
@Override
protected List<Action> retrieveActions(
@CheckForNull SCMSourceEvent event,@NonNull TaskListener listener)
throws IOException,InterruptedException {
return doRetrieve(
new Retriever<List<Action>>() {
@Override
public List<Action> run(
GitClient client,String remoteName,Changes.QueryRequest queryRequest)
throws IOException,InterruptedException {
Map<String,String> symrefs = client.getRemoteSymbolicReferences(getRemote(),null);
if (symrefs.containsKey(Constants.HEAD)) {
// Hurrah! The Server is Git 1.8.5 or newer and our client has symref reporting
String target = symrefs.get(Constants.HEAD);
if (target.startsWith(Constants.R_HEADS)) {
// shorten standard names
target = target.substring(Constants.R_HEADS.length());
}
List<Action> result = new ArrayList<>();
if (StringUtils.isNotBlank(target)) {
result.add(new GitRemoteHeadRefAction(getRemote(),target));
}
result.add(new Gerritlogo());
return result;
}
// Give up,there's no way to get the primary branch
return new ArrayList<>();
}
},new GitSCMSourceContext<>(null,SCMHeadobserver.none()).withTraits(getTraits()),listener,false);
}
/**
* {@inheritDoc}
*/
@Override
public String description() {
String ref = getPayload().getRef();
ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref;
return "Push event to branch " + ref + " in repository " +
getPayload().getRepository().getowner().getUsername() + "/" +
getPayload().getRepository().getName();
}
项目:incubator-netbeans
文件:Utils.java
public static Collection<byte[]> getPaths (Collection<PathFilter> pathFilters) {
Collection<byte[]> paths = new LinkedList<byte[]>();
for (PathFilter filter : pathFilters) {
paths.add(Constants.encode(filter.getPath()));
}
return paths;
}
项目:incubator-netbeans
文件:Utils.java
/**
* Eliminates part of the ref's name that equals knon prefixes such as refs/heads/,refs/remotes/ etc.
* @param ref
* @return
*/
public static String getRefName (Ref ref) {
String name = ref.getName();
for (String prefix : Arrays.asList(Constants.R_HEADS,Constants.R_REMOTES,Constants.R_TAGS,Constants.R_REFS)) {
if (name.startsWith(prefix)) {
name = name.substring(prefix.length());
}
}
return name;
}
public RevCommit getSrcCommit() {
try {
RevWalk revWalk = new RevWalk(git.getRepository());
AnyObjectId headId = git.getRepository().resolve(Constants.HEAD);
RevCommit root = revWalk.parseCommit(headId);
revWalk.sort(RevSort.REVERSE);
revWalk.markStart(root);
return revWalk.next();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
项目:incubator-netbeans
文件:GitTransportUpdate.java
private Type getType (String refName) {
Type retval;
if (refName.startsWith(Constants.R_TAGS)) {
retval = Type.TAG;
} else if (refName.startsWith(Constants.R_REMOTES)) {
retval = Type.BRANCH;
} else if (refName.startsWith(Constants.R_HEADS)) {
retval = Type.BRANCH;
} else if (refName.startsWith(Constants.R_REFS)) {
retval = Type.REFERENCE;
} else {
throw new IllegalArgumentException("UnkNown type for: " + refName);
}
return retval;
}
项目:centraldogma
文件:GitRepositoryTest.java
@Test
public void testDoUpdateRefOnExistingTag() throws Exception {
final ObjectId commitId = mock(ObjectId.class);
assertthatThrownBy(() -> testDoUpdateRef(Constants.R_TAGS + "01/1.0",commitId,true))
.isinstanceOf(StorageException.class);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。