How to Support Case-only Rename in Git

As you may know in IntelliJ IDEA 2016.2 EAP we’ve finally fixed a very annoying issue that didn’t allow to commit case-only renames in IntelliJ IDEA. For a number of reasons, the solution was not so trivial, we decided to share some of its implementation details with you.

When you are on a case-sensitive file system (Linux), case-only renames are just like any other renames, so you’re all good. However, when the file system you’re using is case-insensitive (like Windows or Mac), some of many Git commands will treat changing the file name case as a change, while others won’t. Because of that, a seemingly simple rename of “Myclass.java” to “MyClass.java” makes you face errors you clearly don’t expect. The nature of these errors is in that Git status remains the same, but most of the Git commands will not work with the new name, because the index and the repository still contain the old name.

Turns out that there’s an easy fix for this: just use git mv --force Myclass.java MyClass.java to perform a case-only rename. This will make Git see this rename as a change, and will record it to the index. Of course, we’ve implemented it, and now when you rename a file from IntelliJ IDEA, it will use this command to actually perform it.

However, that is only the tip of an iceberg. I’m not going to mention several places when we relied on system case-sensitivity settings for file paths comparison, which didn’t allow to put two case-only-different paths into a HashSet, and so on. :) Just had to do some debugging for a while and fix all these places.

Things got really interesting when we tried to commit these rename changes, which were already properly recognized by Git. In Git CLI, as well as in most of the clients, you just call git commit and commit everything that is staged. However, in IntelliJ IDEA we call git commit --only -- <paths> which lets commit only selected files, regardless of whether they are staged or not. This allows you, the user, to select paths from the UI and not think about Git indexes. This approach has, of course, a certain downside, but we are working on improvements, and are going, for example, to provide experienced users with a way to manipulate the Git index in the upcoming releases.

The problem here is that Git doesn’t allow the --only syntax for case-only renames, so git commit --only MyClass.java Myclass.java simply fails. We could call git commit without options and commit everything what’s in the index, but what if you’d like to exclude some files from that commit? We had several options on how to deal with these cases, and we decided to stick to the following procedure:

  1. Check what is staged besides case-only renames.
  2. Reset staged changes which are not selected for commit.
  3. Stage what else is needed to be commited.
  4. Commit the staging area.
  5. Stage back the changes unstaged before commit.

If you’re an experienced Git user, you might have noticed that there is a highly improbable case when this procedure will cause an issue: if you have a case-only rename, and you have a file that you don’t want to commit together with this case-only rename, and this file is both partially staged, and partially not-staged, and this separation is important to you (e.g. contains different sorts of changes), then the procedure above will make all changes in the file staged. However, we felt that it is nearly impossible case, and decided not to handle it until we have a GUI for Git staging area and the >git add -p feature.

Please note that as it was described in the beginning of the article, if you rename a file outside of IntelliJ IDEA (via the Terminal or from Finder or Explorer app) without properly calling git mv -f, you’re still doomed. Sorry for that, but that’s because Git won’t see the change at all, and it is not clear how to overcome this problem in IntelliJ IDEA. We are open for suggestions, and would like to implement them if they won’t affect performance or usability in ordinary situations.

Hope you’ll find IntelliJ IDEA helpful enough when you face a case-only rename. If you find any issues with the described approach, please report here or to the tracker.

Posted in New Features | Tagged , | 9 Comments

Java Annotated Monthly – June 2016

Java: past, present and future – we’re still counting down to the release of Java 9, there are ever more resources for getting a handle on what Java 8 can offer us, and the Oracle vs Google court case is over (for now). The language is not the only thing that continues to evolve, well-used libraries like JUnit and Log4J are making the most of modern Java. But with all this change, we need to keep an eye on performance and correctness.

JavaAnnotatedMonthly@2x

Continue reading

Posted in News & Events | Tagged | Leave a comment

IntelliJ IDEA 2016.2 EAP Improves Log for Git and Mercurial

A fresh IntelliJ IDEA 2016.2 EAP build is out and ready to test. Besides usual bugfixes it brings improvements to the Git/Mercurial Log viewer.

The Log viewer now loads in the background on every change (a commit, fetch, rebase, etc). As a result, it’s always ready when you open it.

Also, we’ve reworked the way we show the loading progress. Now, when refreshing, there’s a thin stripe shown under the toolbar.

We hope you’ll enjoy these minor improvements.

If you experience any problems, feel free to file issues directly to the issue tracker.

Develop with Pleasure!

Posted in EAP Releases, New Features | Tagged , , , , | 2 Comments

IntelliJ IDEA 2016.1.3 Update is Available

Good news, everyone! We’ve just released IntelliJ IDEA 2016.1.3, which is a new bugfix update. To see the list of fixes, check out the release notes.

If you’re running IntelliJ IDEA 2016.1, there’s a patch available: click Check for Updates and then Update and Restart. Otherwise, you’re welcome to download the new version from our website.

Develop with Pleasure!

Posted in Releases | Tagged , , | 4 Comments

IntelliJ IDEA 2016.2 EAP: Case-Only Renames in Git, Ligatures, Background Images, and More

Today we’ve released a fresh IntelliJ IDEA 2016.2 EAP build which, among other improvements, finally fixes a very annoying (and highly voted) issue with case-only renames in Git for Windows and OS X. We hope this will make your work simpler when it comes to committing case-only renames from IntelliJ IDEA. Later this week we’ll also share the story behind this issue and how it was fixed, so if you’re interested, stay tuned.

Also, we’re excited to confirm that now we officially support font ligatures (another highly voted request). This feature has been available for some time as experimental and with the latest EAP build we’re ready to make it public.

To enable ligatures, go to the SettingsEditorColors & FontsFont, choose a font that supports ligatures, e.g. FiraCode, Hasklig, Monoid or PragmataPro (the font has to be installed) and select the Enable font ligatures option.

Also we’ve recently reworked the way IntelliJ IDEA displays notifications to make them a little bit more friendly: the popups are now displayed in the rightmost bottom corner (next to the Event Log tool window icon), more compact, and grouped by the subsystem they came from:

The last but not least, we’ve added a new action called Set Background Image. Give your IDE a custom look by choosing a background image for the editor and the IDE frame:

The action is available via Find Action and, for a selected image file, via the context menu for the Project tool window and Image Editor.

In the dialog that pops up, for the editor and the IDE frame, choose a background image, its opacity and position.

In case you see a bug or have a feature request, please go ahead and submit it to our tracker. You feedback is essential for making the IDE better.

Posted in EAP Releases, New Features | Tagged , , , , | 12 Comments

Webinar Recording: Docker for Java Developers

Last week, in partnership with Couchbase, we hosted a webinar focused around Docker. Arun Gupta, a Java Champion and Docker Captain, gave a solid overview of Docker and the IntelliJ IDEA’s plugin for working with it.

The slides from Arun’s presentation can be found at GitHub.

Don’t worry if you missed the webinar. You can watch it right now:

In case you want to jump directly to a topic you’re most interested in, here’re a few links:

During the webinar we had a Q&A session. The questions along with answers can be found in the Arun’s blog. To learn more about IntelliJ IDEA and Docker, read our Docker tutorial.

About the presenter

Arun GuptaArun Gupta is the VP of developer advocacy at Couchbase. He has been built and led developer communities for 10+ years at Sun, Oracle, and Red Hat. Prior to that he led engineering teams at Sun and is a founding member of the Java EE team. You can follow him on Twitter – @arungupta

Develop with Pleasure!

Posted in Webinars | Tagged | Leave a comment

IntelliJ IDEA 2016.2 EAP 162.426.1 is Out

A fresh EAP build for IntelliJ IDEA 2016.2 is out and, being a good EAP build that it is, has something new for you to try:

General

  • A new inspection that warns you when you instantiate new objects inside equals, hashCode, compareTo or Comparator.compare methods. This helps to avoid significant performance problems when, for example, objects of classes with such constructs are added to Set or Map, where these methods will be frequently invoked.

  • Coding assistance for Regex has been extended with better error reporting and added code completion for named group references.

  • The Inspection tool window has been redesigned for better ergonomics: now code location for each of the problems is displayed along with controls to either apply a quick-fix or suppress inspection.

Version control

  • In case a file has been changed after you created a patch, and IntelliJ IDEA cannot find its original revision (e.g. it lost after Rebase, or its format is not supported), IntelliJ IDEA will now prompt you to apply the changes from patch using a Merge-like dialog. Also, in the Apply Patch dialog, before applying a patch you can compare it to your local version using the Show Diff action. While comparing, you can edit your the local version.

 

  • The Git Log can now display commit details for several selected commits (this works for Git and Mercurial).

More information about what else is there can be found in the Release Notes.

To try these new features, download the new EAP build. If you find a bug or a missing feature, don’t forget to write us about it to our tracker or simply share it here in comments.

Develop with Pleasure!

Posted in EAP Releases, New Features | Tagged , , , , , , | 8 Comments

Android SDK Tools 25.1.6 is Out with Better Security

If you’re an Android developer and use the Android Emulator, we strongly recommend you to update your Android SDK Tools to 25.1.6. This update comes with a fix that address a security vulnerability found in the Android Emulator.

To get the update, use the Android SDK Manager.

Develop with Pleasure!

Posted in News & Events | Tagged | Leave a comment

Live Webinar: Refactoring with IntelliJ IDEA

Join us Thursday, June 16th, 12:00 PM – 1:00 PM EDT (New York) / 18:00 – 19:00 CEST (Berlin) (check other time zones) for our free live webinar Refactoring with IntelliJ IDEA, featuring Bill Wake, a senior consultant with Industrial Logic and an author for several books, on XP, refactoring and design patterns.

In this webinar Bill will refactor the Gilded Rose application using IntelliJ IDEA, with its great refactoring tools and coding assistant capabilities. Along the way, you’ll learn some handy IntelliJ IDEA techniques. In this session, you’ll see the Paradox of Duplication in action: increasing duplication can make it easier to remove duplication. Throughout, we’ll show how tests and good habits make it safe to make substantial changes in code.

You’ll see several fundamental refactorings:

  • Restructuring if Statements – to improve control flow
  • Extract Method – to improve readability
  • Change Signature – to change how objects communicate
  • Move Method – to rebalance code between objects

At the end of the webinar, you’ll have an opportunity to access Industrial Logic’s eLearning platform to download the problem code, try the kata and get immediate feedback on your performance with our automated programming critique.

Register now!

Speaking to you

Bill WakeBill is best known in the Agile community as the creator of the the INVEST model for user stories and the Arrange-Act-Assert guideline for unit tests. He has been an author for several books, on XP, refactoring and design patterns. You can follow him on Twitter – @wwake


The Drive to Develop

 

Posted in Webinars | Tagged | 2 Comments

IntelliJ IDEA 2016.2 EAP is Open

Great news, everyone: we’re opening IntelliJ IDEA 2016.2 EAP, a preview of the next IDE update planned for this summer! Besides fixing issues, we’ve also stayed busy working on new features that we hope you’ll like.

New feature highlights include:

  • General
    • The installer for Windows now comes with our custom JDK build where we address some issues with focus and font rendering.
  • Debugger
    • The Watches views has been merged with Variables for more convenience.
    • Multiline expressions are now supported in breakpoint’s Condition and Evaluate and log, and Data Type Renderers.
    • Try and return statements are supported in Evaluate Expression.
  • Version control integration
    • The Commit dialog now shows unversioned files (so you don’t forget to commit something important).
    • Patches can now be applied from the clipboard (the IDE will offer to apply the patch when it obtains focus), or by dragging a file into the IDE.
    • If a file has been moved or renamed since a patch was created for it, the IDE will try to figure that out or let you manually choose the file to apply the patch to.
    • The VCS log continues getting better with a handy loading progress indicator, a shortcut to navigate to the filter field, and tooltips for graph arrows.
  • Editor
    • Better spell-checking suggestions based on Damerau–Levenshtein distance.
    • Language injection now works in YML files.
    • Inspections based on Doclint for detecting Javadoc HTML problems.
  • Settings
    • Importing color schemes from Eclipse.
  • Spring Frameworks
    • Spring 4.3 core features, new inspections and better performance.
    • Better support for Spring Security 4.x.
    • Coding assistance for Spring MVC variables in FreeMarker and Velocity views.
    • Support for generics as qualifiers.
    • A lot of issues related to both Spring and Spring Boot have been fixed.
  • Android

That’s quite a list, huh? More is coming, so stay tuned for additional details on these features soon.

We kindly ask you to give the preview build a try and share your feedback with us. If you see a bug or a missing feature, go ahead and alert us via the tracker. With your help and contributions we’ll make the IDE even better.

Develop with Pleasure!

Posted in EAP Releases, New Features, News & Events | Tagged , | 19 Comments