-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Git integration inside the IDE (commit only) #4704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> | ||
<Properties> | ||
<Property name="defaultCloseOperation" type="int" value="2"/> | ||
<Property name="title" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> | ||
<Connection code="tr("Find")" type="code"/> | ||
</Property> | ||
<Property name="resizable" type="boolean" value="false"/> | ||
</Properties> | ||
<SyntheticProperties> | ||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> | ||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/> | ||
</SyntheticProperties> | ||
<AuxValues> | ||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> | ||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> | ||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> | ||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | ||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | ||
</AuxValues> | ||
|
||
<Layout> | ||
<DimensionLayout dim="0"> | ||
<Group type="103" groupAlignment="0" attributes="0"> | ||
<Group type="102" attributes="0"> | ||
<EmptySpace max="-2" attributes="0"/> | ||
<Group type="103" groupAlignment="0" attributes="0"> | ||
<Group type="102" attributes="0"> | ||
<Component id="commitMessageLabel" min="-2" max="-2" attributes="0"/> | ||
<EmptySpace max="-2" attributes="0"/> | ||
<Component id="commitMessageField" pref="513" max="32767" attributes="0"/> | ||
</Group> | ||
<Component id="buttonsContainer" alignment="0" max="32767" attributes="0"/> | ||
</Group> | ||
<EmptySpace max="-2" attributes="0"/> | ||
</Group> | ||
</Group> | ||
</DimensionLayout> | ||
<DimensionLayout dim="1"> | ||
<Group type="103" groupAlignment="0" attributes="0"> | ||
<Group type="102" alignment="0" attributes="0"> | ||
<EmptySpace max="-2" attributes="0"/> | ||
<Group type="103" groupAlignment="3" attributes="0"> | ||
<Component id="commitMessageLabel" alignment="3" min="-2" max="-2" attributes="0"/> | ||
<Component id="commitMessageField" alignment="3" min="-2" max="-2" attributes="0"/> | ||
</Group> | ||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/> | ||
<Component id="buttonsContainer" min="-2" max="-2" attributes="0"/> | ||
<EmptySpace max="32767" attributes="0"/> | ||
</Group> | ||
</Group> | ||
</DimensionLayout> | ||
</Layout> | ||
<SubComponents> | ||
<Component class="javax.swing.JLabel" name="commitMessageLabel"> | ||
<Properties> | ||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> | ||
<Connection code="tr("Find:")" type="code"/> | ||
</Property> | ||
</Properties> | ||
<AuxValues> | ||
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/> | ||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/> | ||
</AuxValues> | ||
</Component> | ||
<Component class="javax.swing.JTextField" name="commitMessageField"> | ||
<Properties> | ||
<Property name="columns" type="int" value="20"/> | ||
</Properties> | ||
</Component> | ||
<Container class="javax.swing.JPanel" name="buttonsContainer"> | ||
|
||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/> | ||
<SubComponents> | ||
<Component class="javax.swing.JButton" name="cancelButton"> | ||
<Properties> | ||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> | ||
<Connection code="tr("Replace")" type="code"/> | ||
</Property> | ||
</Properties> | ||
<Events> | ||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/> | ||
</Events> | ||
</Component> | ||
<Component class="javax.swing.JButton" name="okButton"> | ||
<Properties> | ||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> | ||
<Connection code="tr("Replace All")" type="code"/> | ||
</Property> | ||
</Properties> | ||
<Events> | ||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okButtonActionPerformed"/> | ||
</Events> | ||
</Component> | ||
</SubComponents> | ||
</Container> | ||
</SubComponents> | ||
</Form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
/* | ||
* This file is part of Arduino. | ||
* | ||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/) | ||
* | ||
* Arduino is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* As a special exception, you may use this file as part of a free software | ||
* library without restriction. Specifically, if other files instantiate | ||
* templates or use macros or inline functions from this file, or you compile | ||
* this file and link it with other files to produce an executable, this | ||
* file does not by itself cause the resulting executable to be covered by | ||
* the GNU General Public License. This exception does not however | ||
* invalidate any other reasons why the executable file might be covered by | ||
* the GNU General Public License. | ||
*/ | ||
|
||
package cc.arduino.view.git; | ||
|
||
import processing.app.Base; | ||
import processing.app.Editor; | ||
import processing.app.Sketch; | ||
import processing.app.helpers.OSUtils; | ||
import processing.app.syntax.SketchTextArea; | ||
|
||
import java.awt.event.WindowEvent; | ||
import java.io.*; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import static processing.app.I18n.tr; | ||
|
||
public class GitCommit extends javax.swing.JFrame { | ||
private final static Logger LOG = Logger.getLogger(SketchTextArea.class.getName()); | ||
private final Editor editor; | ||
|
||
|
||
public GitCommit(Editor editor, Map<String, Object> state) { | ||
this.editor = editor; | ||
|
||
initComponents(); | ||
|
||
Base.setIcon(this); | ||
} | ||
|
||
/** | ||
* This method is called from within the constructor to initialize the form. | ||
* WARNING: Do NOT modify this code. The content of this method is always | ||
* regenerated by the Form Editor. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents | ||
private void initComponents() { | ||
|
||
javax.swing.JLabel commitMessageLabel = new javax.swing.JLabel(); | ||
commitMessageField = new javax.swing.JTextField(); | ||
buttonsContainer = new javax.swing.JPanel(); | ||
cancelButton = new javax.swing.JButton(); | ||
okButton = new javax.swing.JButton(); | ||
|
||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); | ||
setTitle(tr("Commit")); | ||
setResizable(false); | ||
|
||
commitMessageLabel.setText(tr("Message:")); | ||
|
||
commitMessageField.setColumns(20); | ||
|
||
cancelButton.setText(tr("Cancel")); | ||
cancelButton.addActionListener(new java.awt.event.ActionListener() { | ||
public void actionPerformed(java.awt.event.ActionEvent evt) { | ||
cancelButtonActionPerformed(evt); | ||
} | ||
}); | ||
buttonsContainer.add(cancelButton); | ||
|
||
okButton.setText(tr("Ok")); | ||
okButton.addActionListener(new java.awt.event.ActionListener() { | ||
public void actionPerformed(java.awt.event.ActionEvent evt) { | ||
okButtonActionPerformed(evt); | ||
} | ||
}); | ||
buttonsContainer.add(okButton); | ||
|
||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | ||
getContentPane().setLayout(layout); | ||
layout.setHorizontalGroup( | ||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | ||
.addGroup(layout.createSequentialGroup() | ||
.addContainerGap() | ||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | ||
.addGroup(layout.createSequentialGroup() | ||
.addComponent(commitMessageLabel) | ||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | ||
.addComponent(commitMessageField, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)) | ||
.addComponent(buttonsContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | ||
.addContainerGap()) | ||
); | ||
layout.setVerticalGroup( | ||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | ||
.addGroup(layout.createSequentialGroup() | ||
.addContainerGap() | ||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | ||
.addComponent(commitMessageLabel) | ||
.addComponent(commitMessageField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) | ||
.addGap(0, 0, 0) | ||
.addComponent(buttonsContainer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | ||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | ||
); | ||
|
||
pack(); | ||
}// </editor-fold>//GEN-END:initComponents | ||
|
||
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed | ||
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); | ||
}//GEN-LAST:event_cancelButtonActionPerformed | ||
|
||
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed | ||
commit(); | ||
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); | ||
}//GEN-LAST:event_okButtonActionPerformed | ||
|
||
// Variables declaration - do not modify//GEN-BEGIN:variables | ||
private javax.swing.JPanel buttonsContainer; | ||
private javax.swing.JButton cancelButton; | ||
private javax.swing.JTextField commitMessageField; | ||
private javax.swing.JButton okButton; | ||
// End of variables declaration//GEN-END:variables | ||
|
||
private String[] getArgsForProcess(String command) { | ||
String[] args = new String[3]; | ||
if (OSUtils.isWindows()) { | ||
args[0] = "cmd.exe"; | ||
args[1] = "/c"; | ||
} else { //For Mac and Linux | ||
args[0] = "/bin/bash"; | ||
args[1] = "-cl"; | ||
} | ||
|
||
args[2] = command; | ||
|
||
return args; | ||
} | ||
|
||
private void setSystemEnvironment(Map<String, String> environment) { | ||
environment.put("HOME", System.getProperty("user.home")); | ||
environment.put("LANG", "en_US.UTF-8"); | ||
environment.put("GDM_LANG", "en_US.UTF-8"); | ||
environment.put("LANGUAGE", "us"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICS you don't parse the output of git, so why you set the locale to en_US? |
||
} | ||
|
||
private void runCommand(String command, File dir) { | ||
ProcessBuilder processBuilder = new ProcessBuilder(getArgsForProcess(command)); | ||
processBuilder.redirectErrorStream(true); | ||
|
||
setSystemEnvironment(processBuilder.environment()); | ||
|
||
processBuilder.directory(dir); | ||
|
||
try { | ||
Process process = processBuilder.start(); | ||
try (BufferedReader errStream = new BufferedReader(new InputStreamReader(process.getErrorStream())); | ||
BufferedReader cin = new BufferedReader(new InputStreamReader(process.getInputStream()))) { | ||
process.waitFor(); | ||
|
||
String line; | ||
while ((line = errStream.readLine()) != null) { | ||
System.out.println(line); | ||
LOG.log(Level.WARNING, line); | ||
} | ||
|
||
while ((line = cin.readLine()) != null) { | ||
System.out.println(line); | ||
LOG.log(Level.WARNING, line); | ||
} | ||
|
||
if (process.exitValue() == 0) { | ||
System.out.println("Git command successful!"); | ||
LOG.log(Level.FINE, "Git command successful!"); | ||
} | ||
|
||
} catch (InterruptedException e) { | ||
System.out.println(e.getMessage()); | ||
LOG.log(Level.WARNING, e.getMessage()); | ||
} | ||
|
||
} catch (IOException e) { | ||
System.out.println(e.getMessage()); | ||
LOG.log(Level.WARNING, e.getMessage()); | ||
} | ||
} | ||
|
||
private void commit() { | ||
String filePath = editor.getSketch().getMainFilePath(); | ||
StringBuilder command = new StringBuilder(String.format("git add %s && git commit %s ", filePath, filePath)); | ||
|
||
String message = commitMessageField.getText(); | ||
if (!message.isEmpty()) { | ||
command.append(" -m \"") | ||
.append(message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't handle correctly commit messages that contains "quotes" |
||
.append('\"'); | ||
} else { | ||
System.out.println("Commit Failed! Git message wasn't set!"); | ||
LOG.log(Level.WARNING, "Commit Failed! Git message wasn't set!"); | ||
return; | ||
} | ||
|
||
runCommand(command.toString(), editor.getSketch().getFolder()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call directly git?