Perhaps I am looking in the wrong places, but can anyone explain how "Team >> Merge" works within Eclipse? I ended up with instances of git comments interjecting into my code throughout the project, and would like to not have to delete my branch and rebuild.
Example:
<<<<<<< HEAD
static final void method(String input) {
=======
static final void method(String input, int i) {
>>>>>>> master
Your git found a conflict there. You have now both version in your code HEAD and master. You should check which version you want to keep, and remove manually the the rest.
Just literally delete the <<<<<< HEAD stuff, till you only see static final void method(String input) {.
Since I'm working with Android, I didn't use Eclipse in years, but there should be a way to use a GUI for git, so you don't have to delete those lines manually.
Related
Our application needs to use different merge strategies when fetching / merging with JGit. For instance, for any files in conflict that are JSON files, we want to revert any local changes and get THEIRS. If they're not JSON files, we want to keep local changes and merge, even keeping the conflict markers if there are conflicts. However, no matter how I set the merge strategy, I get a CheckoutConflictException (which stops the merge) even if normal command-line git would have done the merge. What am I doing wrong?
public String update() throws Exception {
// We fetch manually and do a dry-run merge to catch any conflicts, so we can reset them
fetch();
Ref fetchHead = this.repo().getRepository().findRef("FETCH_HEAD");
try {
MergeResult mergeResult = this.repo().merge()
.setStrategy(MergeStrategy.RECURSIVE)
.setCommit(false)
.setFastForward(MergeCommand.FastForwardMode.FF)
.include(fetchHead)
.call();
} catch (CheckoutConflictException cce) {
List<String> conflicts = cce.getConflictingPaths();
if (conflicts != null && conflicts.size() > 0) {
for (String file : conflicts) {
if (file.endsWith(".json")) {
revert(Paths.get(file));
}
}
}
}
/// ... and now that we've reverted any conflicted JSON files, we can try the merge for real
MergeResult mergeResult = this.repo().merge()
.setStrategy(MergeStrategy.RECURSIVE)
.setCommit(true)
.setFastForward(MergeCommand.FastForwardMode.FF)
.include(fetchHead)
.call();
return mergeResult.getMergeStatus().toString();
}
I was able to get the behavior I wanted using stashCreate() and stashApply(). Specifically, stashCreate() to stash any changes left after reverting any JSON files, then using PullCommand (not MergeCommand) to pull any new changes, then using stashApply() to apply any stashed local changes. I tested it with no conflicts, conflicts in JSON files, conflicts in other files where different parts of the file were changed between local and remote, and other files where the same line(s) were changed. It worked in all of the above cases.
I'm trying to understand how to use the .gitattributes from JGit. But I'm unable to find any tutorial which best demonstrates it.
Is it that JGit hasn't support for it. But git client has this support. Why not JGit?
JGit has basic support for .gitattributes. See bug 342372 and related bugs for the current state of development.
The JGit test suite may help you understanding how .gitattributes are implemented in JGit. See this article for how to work with the JGit sources.
If you would like to try libgi2, there is a jni bindings that allows you to access most recent libgit2 attributes apis
Following are some examples:
Repository testRepo = Repository.open("path-to-your-repo");
// load macros from .gitattributes file
Attr.addMacro(testRepo, "binary", "-diff -crlf");
// Loop through all attributes
Map<String, String> attributes = new HashMap<>();
Attr.foreach(
testRepo,
EnumSet.of(CHECK_INDEX_THEN_FILE),
".",
new Attr.ForeachCb() {
#Override
public int accept(String name, String value) {
attributes.put(name, value);
return 0;
}
});
You can find the test case about these apis here
FindBugs seems to show only the first occurrence of a particular bug in each method. This occurs in Eclipse as well as in the FindBugs stand-alone client.
How can I configure FindBugs to show all occurrences?
Example:
import javax.annotation.Nonnull;
public class Bar
{
public void meth(#Nonnull final String pArg) {
System.out.println(pArg);
}
public void foo() {
String s = null;
meth(s); // <<== bug marker here (NP_NONNULL_PARAM_VIOLATION)
meth(null); // no bug marker here
meth(s); // and none here either :-(
}
}
Im am using the latest FindBugs 2.0.2 Eclipse plugin (with Eclipse 3.6).
The problem appears to depend on the bug pattern. For example, I see more than one hit per method with DLS_DEAD_LOCAL_STORE, but not with NP_NONNULL_PARAM_VIOLATION. The latter is shown above.
Thanks!
It seems that Findbugs only checks those lines of code for this specific error, which can actually be reached according to a control flow analysis. With your 3 method invocations, the first one leads to a NPE, therefore the second and third will never be reached.
There have been similar bug reports for previous versions: http://sourceforge.net/p/findbugs/bugs/980/
I am very new to developing eclipse plugins. The biggest hurdle I am facing right now is where/how to get at the data from various other plugins. I am having a real hard time finding documentation for this. For instance the Team Provider plugin....
How do I read the svn revision of a file? Lets say I have an IResourceChangeListener and I want to keep track of the svn revision number of a file (if the user did an update for example).
If I want to ask svn if there are pending updates for a project, how do I talk to the eclipse team provider?
I am not sure where to start...
Thanks!
I eventually discovered what I was looking for after many hours of searching. Unfortunately since I have less than 100 rep. I have been unable to post until now....
I am making a little progress on this. I randomly stumbled upon this while pouring through eclipse source code.
The following code snippet monitors everything that goes on with regard to an svn enabled project. If you save a file, to an update, revert etc. Anything that touches the files or meta data of the files. I just print out the file/direcory name and its revision number.
Subversive version:
final Subscriber subscriber = UpdateSubscriber.instance();
subscriber.addListener(new ISubscriberChangeListener() {
#Override
public void subscriberResourceChanged(ISubscriberChangeEvent[] events) {
for(ISubscriberChangeEvent event : events) {
UpdateSyncInfo info = (UpdateSyncInfo) subscriber.getSyncInfo(event.getResource());
System.out.println(event.getResource().getName()+" revision: "+uInfo.getLocalResource().getRevision());
}
}
});
The real trick was figuring out the entry point to get at this information: UpdateSubscriber. It would be nice if there was a good resource for finding out this sort of information.
Subclipse version:
private static final Subscriber subscriber = SVNWorkspaceSubscriber.getInstance();
private static final ISubscriberChangeListener subsciberListener = new ISubscriberChangeListener() {
#Override
public void subscriberResourceChanged(ISubscriberChangeEvent[] events) {
try {
for (ISubscriberChangeEvent event : events) {
SVNStatusSyncInfo info = (SVNStatusSyncInfo) subscriber.getSyncInfo(event.getResource());
System.out.println(event.getResource().getName() + " revision: " + info.getRepositoryRevision());
}
} catch (TeamException e) {
}
}
};
#Override
public void start(BundleContext context) throws Exception {
super.start(context);
subscriber.addListener(subsciberListener);
}
#Override
public void stop(BundleContext context) throws Exception {
subscriber.removeListener(subsciberListener);
super.stop(context);
}
For general information on the Team API in the Eclipse platform, review the documentation in the help system.
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/team.htm
(If you're working with the Subscriber stuff, it appears that's mentioned under the "Synchronization Support" -> "Beyond the Basics" topic.)
The Java doc for the team packages also helps:
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/team/core/package-summary.html
If you're trying to integrate with or otherwise extend the Subclipse or Subversive team providers, you may have better luck asking your question in their forums:
http://subclipse.tigris.org/ds/viewForums.do
http://www.eclipse.org/subversive/newsgroup.php
One starting point would be to explore the sources of subversive to see how they did their implementation of the features you are describing.
The sources for eclipse.team (the common module for all VCS plugins) are available in a Git repo.
The sources for EGit, another VCS plugin (for Git) can also be instructive.
I believe the title says it. I'm new to source control thingy.
So, let's say I have two developers working on the same project and they started editing the same file(s) at the same time then everyone of them send the new version at a slightly different time. From what I understand the one who sends the changes last will have his changes kept, the other one's code will be in the archive only!!!
Is that correct?
Please clarify. Thanks.
No, that's not quite correct. It depends somewhat on which version control software you're using, but I like Git so I'll talk about that.
Suppose we have a file Foo.java:
class Foo {
public void printAWittyMessage() {
// TODO: Be witty
}
}
Alice and Bob both modify the file. Alice does this:
class Foo {
public void printAWittyMessage() {
System.out.println("Alice is the coolest");
}
}
and Bob does this:
class Foo {
public void printAWittyMessage() {
System.out.println("Alice is teh suk");
}
}
Alice checks her version in first. When Bob attempts to check his in, Git will warn him that there is a conflict and won't allow the commit to be pushed into the main repository. Bob has to update his local repository and fix the conflict. He'll get something like this:
class Foo {
public void printAWittyMessage() {
<<<<< HEAD:<some git nonsense>
System.out.println("Alice is the coolest");
=====
System.out.println("Alice is teh suk");
>>>>> blahdeblahdeblah:<some more git nonsense>
}
}
The <<<<<, ===== and >>>>> markers show which lines were changed simultaneously. Bob must resolve the conflict in some sensible way, remove the markers, and commit the result.
So what eventually lives in the repository is:
Original version -> Alice's version -> Bob's conflict-fixed version.
To summarise: the first to commit gets in without any problems, the second to commit must resolve the conflict before getting into the repository. You should never end up with someone's changes being clobbered automatically. Obviously Bob can resolve the conflict incorrectly but the beauty of version control is that you can roll back the incorrect fix and repair it.
Much depends on the system you're using.
However in the common case is: who commits his changes second would have to perform a "merge" operation. Meaning s/he would need to compare the two files and come up with a merged version. However (!) many popular system (including IDE) comes with smart tools to assist you doing that.
Here are some tools like that compared:
http://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools