I'm trying to access specific commitId files using the JGit library.
Using Git command this would look like : git checkout [COMMIT_ID], then my folder would checkout to the specific commit and get any file from it.
Now using JGit, I'm calling the Git.cloneRepository() function to get my repository (can't clone from a specific commitId here I think sadly). Then I'm trying to checkout using this : gitRepo.checkout().setName(gitCommitId).call()
But this is getting me the folliwing error : Remote origin did not advertise Ref for branch COMMIT_ID. This Ref may not exist in the remote or may be hidden by permission settings.
Which is odd because the CLI git command does work.
Maybe it is not something feasible through this lib but I didn't find anything else on the web yet.
setName(String name) is more for branch name, not for commit ID.
setStartPoint(RevCommit startCommit) does use a commit ID.
As seen here, git.checkout().setAllPaths(true).setStartPoint(gitCommitId).call(); would work better after your clone.
Related
I am having an issue of my git HEAD going backwards by certain days length when I do the following
Complete my changes in my Sprint1.4Branch and add all files, then commit my files to local branch of Sprint1.4Branch ($git commit -m "message")
Then check out to "LifeGoals" local branch($ git checkout LifeGoals). LifeGoals is the branch(created by cloning from the git repository) from which I created my local Sprint1.4Branch to do my sprint specific user story coding.
Merge Sprint1.4Branch in to local LifeGoals ( $ git merge Sprint1.4Branch)
Push local LifeGoals branch to remote 'origin' ($git push origin LifeGoals) Note: Only LifeGoals has upstream connection to remote origin. Sprint1.4Branch is purely local branch alone.
Check out to local branch of 'Sprint1.4Branch' to get back in to local branch to make further changes. ($git checkout Sprint1.4Branch)
I see that some of the files in my IDE are moved to a status which is few days back wards.
What is the mistake I am doing ?
At least I have my commits to go back to, I believe.
I am trying to copy the the snapshot from my google cloud instance to the google bucket.
Maven is being used to compiling the code into a snapshot and snapshot is available at the below location -
/home/bhaskarhnarula/getting-started-java/bookshelf/6-gce/bookshelf-6-1.0-SNAPSHOT.war
In my build file, in my build sh, I am giving the following copy command which is throwing CommandException as below -
CommandException: No URLs matched: target/bookshelf-1.0-SNAPSHOT.war
Below command is used for moving the snapshot to the cloud -
+ gsutil cp target/bookshelf-1.0-SNAPSHOT.war gs://cloudpoc2bucket
Aim is to host a sample application on a new instance created in Google Cloud via Google-Compute-Engine. Any leads would be helpful. Thanks!
No clue if you figured it out, but I ran into the same issue and found out that there was a typo in the script in the example; target/bookshelf-1.0-SNAPSHOT.war doesn't exist, it's actually called target/bookshelf-6-1.0-SNAPSHOT.war. The error makes complete sense then, since the script's asking gsutils to upload a non-existent file. So if you look in the makeBookshelf script, you should see a line labeled
WAR=bookshelf-1.0-SNAPSHOT.war
it should actually be
WAR=bookshelf-6-1.0-SNAPSHOT.war
Edit that and it should run perfectly fine.
I've already sent in a pull request to get this fixed in the repository. Hope you figured it out!
when i am trying to get latest code from repository "git pull origin master"
a message appear,
error: Your local changes to the following files would be overwritten by merge:
profile-summary-portlet/.project
Please, commit your changes or stash them before you can merge.
I dont want it to merege.
then make a git reset --hard
after that try to pull again.
your local data will be overwritten by this command! So be careful...
Well, the message says it all =). You can stash the changes and apply after if you do not want to merge now.
http://git-scm.com/book/en/Git-Tools-Stashing
I want to access the ChangeSets of SVN, CVS and Git programatically via Java. I.e. I want the data which is shown in the "Synchronize"-view.
I tried several approaches to find the correct usage in the code, and here's the few documentation I could find (but without success):
I managed to access the Synchronize-View via TeamUI.getSynchronizeManager(), but not the changesets.
An other thing I tried was to get the cangesets via FocusedTeamUiPlugin.getDefault().getContextChangeSetManagers() (got the manager and then the ChangeSetProvider where I tried to get the ChangeSets) - but they always are empty (because they are created when I first call it).
So, how can I access ChangeSets (with Java) in Eclipse (Mylyn)? In the end, I need the number of commits and code churn (loC added/removed/edited). Or is there probably an other, better approach?
Any help is appreciated really much!
I don't think Eclipse has implemented this feature as a public API yet. However, these links may help:
Internal changeset class and other API: http://www.cct.lsu.edu/~rguidry/ecl31docs/api/index.html?org/eclipse/team/internal/core/subscribers/ChangeSet.html
A feature enhancement request where they talk about why they haven't implemented it yet (but it's dated 2008, however the bug is still open?) https://bugs.eclipse.org/bugs/show_bug.cgi?id=116084
Sorry I couldn't be of more help! Maybe this will help you in the right direction...
You could perhaps go around Eclipse:
Apply rsync to get the CVS "*,v" files from the CVS server. It works for me.
Apply cvs2svn's "cvs2git" command to the CVS repos. It works for me.
Apply "git svn clone" (documented under "git-svn") to the SVN repos. I have not tried it.
Finally, use JGit's API to get the changesets from all of the repos, which at this point are all git repos. I think you'll particularly need these:
class Git
class FileResolver
class BaseConnection
interface Repository
class CheckoutCommand
class LogCommand
class RevCommit
class DiffCommand
class DiffEntry
class DiffFormatter
I've looking for this for 1 month now.
I tried to programm a plugin for eclipse, which is able to read the changeset of a Project ("working copy" of the repository).
What I've done now is an ugly work-around.
I used Runtime.exec() to run a cmd-command / Shell- command.
If you install a svn-commandline Client, you can type svn status -v -u
It gives you a list of all files of the working copy with the changeset info.
Then you can parse through the list to find all lines which start with "M" - for "modified" to get the Path of the changed file.
Today I signed up for github, and converted an existing filesystem into a git repo using the technique described here:
http://crashingdaily.wordpress.com/2009/09/02/initing-a-new-remote-git-repository-with-existing-files/
Most importantly (I think) it involved this line:
git --bare init
I then followed the rest of github.com's setup tutorials (this was part of that) and was done. The existing filesystem was within Dropbox, so I performed the same setup on the two other machines that use the filesystem (now a git repo).
Tonight I tried to get JGit to add a file, commit it and then push it. Here's the gist of the code up until the point it breaks:
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File("path/to/my/repo"))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
Git git = new Git(repository);
AddCommand add = git.add();
try{
add.addFilepattern("PlayState.as").call();`
This is basically taken verbatim from a JGit tutorial, incidentally. It throws an exception at that last quoted line and states:
org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
at org.eclipse.jgit.lib.Repository.getIndexFile(Repository.java:838)
at org.eclipse.jgit.lib.Repository.lockDirCache(Repository.java:886)
at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:136)
at flipa.FLIPAGame.writeToFlixel(FLIPAGame.java:77)
at flipa.FLIPAGame.main(FLIPAGame.java:58)
Now, I'm not saying it's unreasonable to claim that, because truth be told I am not the best friend of version control. I get that a bare repo is one with just git in and no other files, but it seems to me that now it has files in it. I've already manually added, committed and pushed to github using git from Terminal. So I can't immediately see why it won't even recognise the repo.
Any takers?
EDIT - For clarification, killing off this repo is no big deal if someone can propose another solution. I want a git repo to use the filesystem in my dropbox, and be able to commit to github via Java.
For your code, I would say the options setGitdir() and findGitDir() are not supposed to be used at the same time.
To retrieve an existing repository, I use findGitDir(new File("path/to/my/repo") and it is enough.
This sounds like you've added the files to a bare repository. A bare repository should not be touched, except through git push and pull commands (or git commands in general). As a guide, I don't ever look in my bare repositories.
It should be used as a central location. Once you've created the git bare repo, you should clone it and then work on it from the clone, pushing and pulling from the clone.
$ cd /dropbox/repo
$ git init --bare
$ cd /workdir
$ git clone file:///dropbox/repo
$ add files in here
$ git add .
$ git commit -m "initial version"
$ git push origin master
$ more changes here
$ git add etc.
The difference between this and github is the git clone, which then comes from a different place. To be quite honest, unless you've got a really good reason to have a local copy, I'd just forget about the dropbox repo and just use github.
Your third line of code, right after .build(); should be:
repository.create();
This is the equivalent of the "git init" command.
In your case since you are working in an existing directory, you may find more convenient using Git.open().
Git git = Git.open(new File(".git"));
System.out.println("Repository: " + git.getRepository().toString());
//Do some git action for instance:
RevCommit rev = git.commit().setAmend(true)
.setAuthor("me", "me#mail.com")
.setMessage("Testing commit from jGit").call();
git.close();
Source: Article written by RĂ¼diger Herrmann available in Code Affine.