Unable to add and commit a file to a subversion repository.
With the following code snippet:
SVNCommitClient svnCommitClient = svnClientManager.getCommitClient();
svnCommitClient.doCommit(new File[]{new File("project/README.txt")}, false, "Commit message", null, null, false, false, SVNDepth.INFINITY);
I get the following exception:
Exception in thread "main" org.tmatesoft.svn.core.SVNException: svn: E200009: Commit failed (details follow):
svn: E200009: 'D:\Java\POC\SvnKit\project\README.txt' is not under version control
Prompt what I did wrong, and I would like to see an example of how to
Welcome to Stackoverflow,
like the exception already tells you, the file you want to be committed is not under version control yet, so you have to add it first.
On your CommitEditor you should call something like this:
SVNRepository repository = SVNRepositoryFactory.create( SVNURL.parseURIDecoded( url ) );
ISVNEditor editor = repository.getCommitEditor( logMessage , null /*locks*/ , true /*keepLocks*/ , null /*mediator*/ );
//the second and the third parameters are the path and revision respectively
//of the item's ancestor if the item is being added with history
editor.addFile( "your/path/project/README.txt" , null , -1 );
You should also have a look at the full example at SVNKit
Related
I have been trying to get git comit log for a specific file in git repo, but after multiple attempts I am failing to identify the source of the problem.
Here is the link to my github code.
PS: The files Folder needs to be deleted everytime the app needs to start again. Any tips on that would be also helpful.
To put it in short, I tried the below piece of code to get the commit log, but I am getting a null RevCommit.
Repository repository = git.getRepository();
//Approach 1
RevCommit commits = git.log().addPath("D:/Code_downloads/fileaccess/files/dev/Doc2.csv").call().iterator().next();
//Approach 2
RevWalk revWalk = new RevWalk( repository );
revWalk.markStart( revWalk.parseCommit( repository.resolve( Constants.HEAD ) ) );
revWalk.setTreeFilter(PathFilter.create( "D:/Code_downloads/fileaccess/files/dev/Doc2.csv" ) );
revWalk.sort( RevSort.COMMIT_TIME_DESC );
revWalk.sort( RevSort.REVERSE, true );
RevCommit commit = revWalk.next();
Referred multiple documentations and stackoverflow posts. no luck.
https://archive.eclipse.org/jgit/site/4.5.0.201609210915-r/apidocs/org/eclipse/jgit/api/LogCommand.html
Any help will be appreciated.
It should work to use addPath() and then iterate over the RevCommits.
But you should not use the "absoulte path" to the file, but rather only the relative path inside your repository.
E.g.
Iterable<RevCommit logs = git.log().addPath("README.md").call();
for (RevCommit rev : logs) {
System.out.println("Commit: " + rev + ", name: " + rev.getName() + ", id: " + rev.getId().getName());
}
There is a ready-to-run snippet in the jgit-cookbook which shows a few more ways to iterate commits.
I am trying to integrate Git in my existing RCP application,
For that i have imported egit.core and egit.io plugin as source project into my application and when i tried to commit the file using egit's commit() from CommitOperation Class i am getting the below exception:
Caused by: org.eclipse.jgit.api.errors.JGitInternalException: Entry not found by path: D:\Test\file.txt
at org.eclipse.jgit.api.CommitCommand.createTemporaryIndex(CommitCommand.java:414)
at org.eclipse.jgit.api.CommitCommand.call(CommitCommand.java:194)
at org.eclipse.egit.core.op.CommitOperation.commit(CommitOperation.java:255)
... 39 more
And when i debugged through the code to find out where the exception is happening, it is on CommitCommand.class at the following point
// there must be no unprocessed paths left at this point; otherwise an
// untracked or unknown path has been specified
for (int i = 0; i < onlyProcessed.length; i++)
if (!onlyProcessed[i])
throw new JGitInternalException(MessageFormat.format(
JGitText.get().entryNotFoundByPath, only.get(i)));
I have no idea what the unprocessed path here is meant by?
I am able to access the path. can anyone help me how to proceed further
I'm trying to pull the remote master branch in my currently checked out local branch. Here's the code for it
checkout.setName(branchName).call();
PullCommand pullCommand = git.pull();
System.out.println("Pulling master into " + branchName + "...");
StoredConfig config = git.getRepository().getConfig();
config.setString("branch", "master", "merge", "refs/heads/master");
pullCommand.setRemote("https://github.com/blackblood/TattooShop.git");
pullCommand.setRemoteBranchName("master");
pullResult = pullCommand.setCredentialsProvider(credentialsProvider).call();
When I run the code I get the following error on this line pullCommand.setRemote("https://github.com/blackblood/TattooShop.git");
Error :
org.eclipse.jgit.api.errors.InvalidConfigurationException:
No value for key remote.https://github.com/blackblood/TattooShop.git.url found in configurationCouldn't pull from remote. Terminating...
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:247)
at upload_gen.Launcher.updateFromRemote(Launcher.java:179)
at upload_gen.Launcher.main(Launcher.java:62)
Following are the contents of my .git/config file
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
url = https://github.com/blackblood/TattooShop.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "heroku"]
url = git#heroku.com:tattooshop.git
fetch = +refs/heads/*:refs/remotes/heroku/*
This seems to be a bug in JGit. According to the JavaDoc of setRemote(), it sets the remote (uri or name) to be used for the pull operation but apparently only the remote name works.
Given your configuration you can work around the issue by using the remote name like this:
pullCommand.setRemote( "origin" );
I recommend to open a bug report in the JGit bugzilla so that this gets fixed in future versions of JGit.
I am trying to access Revision History of a file that has been deleted using SVNKit.
Following is what I am doing to achieve that.
SVNClientManager manager = SVNClientManager.newInstance();
SVNLogClient logClient = manager.getLogClient();
logClient.doLog(svnURL, new String[] { fileName }, SVNRevision.create(deletedRevision),
SVNRevision.UNDEFINED, SVNRevision.UNDEFINED, false, false, true, -1, null,
new ISVNLogEntryHandler() {
public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
log.debug(" ==== " + logEntry.getChangedPaths() + " === "
+ logEntry.getRevision());
}
});
Here, deletedRevision => The SVN revision in which File was deleted.
When this code is executed I keep on getting following exceptions:
org.tmatesoft.svn.core.SVNException: svn: '<FilePath>' path not found: 404 Not Found (https://<RepositoryURL>
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:64)
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:51)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.logImpl(DAVRepository.java:976)
at org.tmatesoft.svn.core.io.SVNRepository.log(SVNRepository.java:1034)
at org.tmatesoft.svn.core.wc.SVNLogClient.doLog(SVNLogClient.java:1024)
at org.tmatesoft.svn.core.wc.SVNLogClient.doLog(SVNLogClient.java:891)
at com.blueoptima.connectors.scr.SVN.getWorkingFileList(SVN.java:711)
... 4 more
Is it something that I am doing wrong here? Is there any other way to get the History of a deleted file using SVNKit
Though this question has been asked more than a year back but still thought of answering it if it could be other's help.
I didnt try for retrieving history of a deleted file but i could retrieve the history of a deleted branch using -
SVNLogClient.doLog(SVNURL.parseURIEncoded(path), new String[] { "" }, pegRevision, SVNRevision.create(0),pegRevision, stopOnCopy, discoverChangedPaths, logsLimit, logHandler);
This is similar to the call you are making but you need to supply proper values for pegRevision, startRevision and endRevision. Use of UNDEFINED may not give correct result, instead use the revision at which file was deleted as pegRevision and startRevision as 0 and it should work.
You should specify a revision where the file existed as a peg revision. Obviously it is deletedRevision-1. And maybe (I'm not sure here, just try) the file should exist in both start and end revisions.
Using the p4java library from Perforce (http://kb.perforce.com/article/1086/p4java-api), I'm trying to find out what files in a changelist are unresolved and need to be resolved before I can submit them.
IChangelist changelist = getServer().getChangelist(changelistId);
List<IFileSpec> changelistPendingFiles = changelist.getFiles(false);
In this List, I'm trying to figure out which IFileSpec still need to be resolved.
Something like this:
for (IFileSpec pendingFile : changelistPendingFiles) {
// How to find out if pendingFile needs to be resolved?
FileAction action = pendingFile.getAction();
// The above results in "FileAction.EDIT",
// but that doesn't tell me anything about the unresolved state
// The "diffStatus" variable for this pendingFile is "pending"
// The "howResolved" variable for this pendingFile is null
// The "opStatus" variable for this pendingFile is VALID
}
Thanks for anything you can provide!
The comprehensive way is to run P4Java's version of the fstat command, and check if the file needs resolving. Here's a code sample (not guaranteed to be bulletproof) that works in a simple test case.
List<IExtendedFileSpec> extfiles = server.getExtendedFiles(changelistPendingFiles,
-1,
-1,
-1,
new FileStatOutputOptions(false, false, false, false, false, true),
null);
for(IExtendedFileSpec extfile : extfiles) {
System.out.println(extfile.isUnresolved());
}
In the FileStatOutputOptions, I'm asking for information on files that are open and need resolving. The isUnresolved method should tell you what you want.
Hope that helps!