This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 215636
Collapse All | Expand All

(-)a/libs.git/apichanges.xml (+13 lines)
Lines 111-116 Link Here
111
        
111
        
112
        <change>
112
        <change>
113
            <api name="gitlibrary_api"/>
113
            <api name="gitlibrary_api"/>
114
            <summary>Adding new method to GitClient: commit(), amending the last commit</summary>
115
            <version major="1" minor="7"/>
116
            <date day="29" month="1" year="2013"/>
117
            <author login="ovrabec"/>
118
            <compatibility addition="yes"/>
119
            <description>
120
                Git supports commit amendments, in other words modifying the last commit and changing its
121
                commit message or modified files. Another commit method allows API clients to specify
122
                either to amend the last commit or to make a fresh new commit on top of current HEAD.
123
            </description>
124
        </change>
125
        <change>
126
            <api name="gitlibrary_api"/>
114
            <summary>Adding new method to GitClient: release()</summary>
127
            <summary>Adding new method to GitClient: release()</summary>
115
            <version major="1" minor="5"/>
128
            <version major="1" minor="5"/>
116
            <date day="16" month="11" year="2012"/>
129
            <date day="16" month="11" year="2012"/>
(-)a/libs.git/manifest.mf (-1 / +1 lines)
Lines 1-4 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.libs.git/1
2
OpenIDE-Module: org.netbeans.libs.git/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/libs/git/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/libs/git/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.6
4
OpenIDE-Module-Specification-Version: 1.7
(-)a/libs.git/src/org/netbeans/libs/git/GitClient.java (-1 / +15 lines)
Lines 342-349 Link Here
342
     * @throws GitException an unexpected error occurs
342
     * @throws GitException an unexpected error occurs
343
     */
343
     */
344
    public GitRevisionInfo commit(File[] roots, String commitMessage, GitUser author, GitUser commiter, ProgressMonitor monitor) throws GitException {
344
    public GitRevisionInfo commit(File[] roots, String commitMessage, GitUser author, GitUser commiter, ProgressMonitor monitor) throws GitException {
345
        return commit(roots, commitMessage, author, commiter, false, monitor);
346
    }
347
    
348
    /**
349
     * Commits all changes made in the index to all files under the given roots
350
     * @param roots files or folders to recursively commit.
351
     * @param commitMessage commit message
352
     * @param author person who is the author of the changes to be committed
353
     * @param commiter person who is committing the changes, may not be the same person as author.
354
     * @param amend amends and modifies the last commit instead of adding a completely new commit
355
     * @param monitor progress monitor
356
     * @throws GitException an unexpected error occurs
357
     */
358
    public GitRevisionInfo commit(File[] roots, String commitMessage, GitUser author, GitUser commiter, boolean amend, ProgressMonitor monitor) throws GitException {
345
        Repository repository = gitRepository.getRepository();
359
        Repository repository = gitRepository.getRepository();
346
        CommitCommand cmd = new CommitCommand(repository, getClassFactory(), roots, commitMessage, author, commiter, monitor);
360
        CommitCommand cmd = new CommitCommand(repository, getClassFactory(), roots, commitMessage, author, commiter, amend, monitor);
347
        cmd.execute();
361
        cmd.execute();
348
        return cmd.revision;
362
        return cmd.revision;
349
    }
363
    }
(-)a/libs.git/src/org/netbeans/libs/git/jgit/commands/CommitCommand.java (-2 / +7 lines)
Lines 89-103 Link Here
89
    private final GitUser author;
89
    private final GitUser author;
90
    private final GitUser commiter;
90
    private final GitUser commiter;
91
    public GitRevisionInfo revision;
91
    public GitRevisionInfo revision;
92
    private final boolean amend;
92
93
93
    public CommitCommand (Repository repository, GitClassFactory gitFactory, File[] roots, String message, GitUser author, GitUser commiter, ProgressMonitor monitor) {
94
    public CommitCommand (Repository repository, GitClassFactory gitFactory, File[] roots, String message, GitUser author, GitUser commiter, boolean amend, ProgressMonitor monitor) {
94
        super(repository, gitFactory, monitor);
95
        super(repository, gitFactory, monitor);
95
        this.roots = roots;
96
        this.roots = roots;
96
        this.message = message;
97
        this.message = message;
97
        this.monitor = monitor;
98
        this.monitor = monitor;
98
                
99
        this.author = author;
99
        this.author = author;
100
        this.commiter = commiter;
100
        this.commiter = commiter;
101
        this.amend = amend;
101
    }
102
    }
102
103
103
    @Override
104
    @Override
Lines 151-156 Link Here
151
                }
152
                }
152
                
153
                
153
                commit.setMessage(message);
154
                commit.setMessage(message);
155
                commit.setAmend(amend);
154
                RevCommit rev = commit.call();
156
                RevCommit rev = commit.call();
155
                revision = getClassFactory().createRevisionInfo(rev, repository);
157
                revision = getClassFactory().createRevisionInfo(rev, repository);
156
            } finally {
158
            } finally {
Lines 242-247 Link Here
242
    @Override
244
    @Override
243
    protected String getCommandDescription () {
245
    protected String getCommandDescription () {
244
        StringBuilder sb = new StringBuilder("git commit -m ").append(message); //NOI18N
246
        StringBuilder sb = new StringBuilder("git commit -m ").append(message); //NOI18N
247
        if (amend) {
248
            sb.append(" --amend"); //NOI18N
249
        }
245
        for (File root : roots) {
250
        for (File root : roots) {
246
            sb.append(" ").append(root); //NOI18N
251
            sb.append(" ").append(root); //NOI18N
247
        }
252
        }
(-)a/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CommitTest.java (-2 / +48 lines)
Lines 56-64 Link Here
56
import org.eclipse.jgit.lib.*;
56
import org.eclipse.jgit.lib.*;
57
import org.eclipse.jgit.revwalk.RevCommit;
57
import org.eclipse.jgit.revwalk.RevCommit;
58
import org.eclipse.jgit.treewalk.TreeWalk;
58
import org.eclipse.jgit.treewalk.TreeWalk;
59
import org.eclipse.jgit.treewalk.WorkingTreeOptions;
60
import org.eclipse.jgit.treewalk.filter.PathFilter;
59
import org.eclipse.jgit.treewalk.filter.PathFilter;
61
import org.eclipse.jgit.util.io.AutoCRLFOutputStream;
62
import org.netbeans.libs.git.GitClient;
60
import org.netbeans.libs.git.GitClient;
63
import org.netbeans.libs.git.GitException;
61
import org.netbeans.libs.git.GitException;
64
import org.netbeans.libs.git.GitStatus;
62
import org.netbeans.libs.git.GitStatus;
Lines 620-623 Link Here
620
            assertEquals(e1.getObjectId(), walk.getObjectId(0));
618
            assertEquals(e1.getObjectId(), walk.getObjectId(0));
621
        }
619
        }
622
    }
620
    }
621
    
622
    public void testAmendCommit () throws Exception {
623
        repository.getConfig().setString("user", null, "name", "John");
624
        repository.getConfig().setString("user", null, "email", "john@git.com");
625
        repository.getConfig().save();
626
627
        File dir = new File(workDir, "testdir");
628
        File newOne = new File(dir, "test.txt");
629
        File another = new File(dir, "test2.txt");
630
        dir.mkdirs();
631
        write(newOne, "content1");
632
        write(another, "content2");
633
634
        GitClient client = getClient(workDir);
635
        client.add(new File[] { newOne, another }, NULL_PROGRESS_MONITOR);
636
        GitRevisionInfo info = client.commit(new File[] { newOne, another }, "initial commit", null, null, NULL_PROGRESS_MONITOR);
637
        Map<File, GitStatus> statuses = client.getStatus(new File[] { newOne, another }, NULL_PROGRESS_MONITOR);
638
        assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
639
        assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
640
        
641
        write(newOne, "modification1");
642
        write(another, "modification2");
643
644
        client.add(new File[] { newOne, another }, NULL_PROGRESS_MONITOR);
645
        GitRevisionInfo lastCommit = client.commit(new File[] { newOne }, "second commit", null, null, false, NULL_PROGRESS_MONITOR);
646
        statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR);
647
        assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
648
        assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false);
649
        Map<File, GitFileInfo> modifiedFiles = lastCommit.getModifiedFiles();
650
        assertTrue(modifiedFiles.get(newOne).getStatus().equals(Status.MODIFIED));
651
        assertNull(modifiedFiles.get(another));
652
653
        assertEquals(1, lastCommit.getParents().length);
654
        assertEquals(info.getRevision(), lastCommit.getParents()[0]);
655
        assertEquals(lastCommit.getRevision(), client.getBranches(false, NULL_PROGRESS_MONITOR).get("master").getId());
656
        
657
        lastCommit = client.commit(new File[] { newOne, another }, "second commit, modified message", null, null, true, NULL_PROGRESS_MONITOR);
658
        statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR);
659
        assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
660
        assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
661
        modifiedFiles = lastCommit.getModifiedFiles();
662
        assertTrue(modifiedFiles.get(newOne).getStatus().equals(Status.MODIFIED));
663
        assertTrue(modifiedFiles.get(another).getStatus().equals(Status.MODIFIED));
664
665
        assertEquals(1, lastCommit.getParents().length);
666
        assertEquals(info.getRevision(), lastCommit.getParents()[0]);
667
        assertEquals(lastCommit.getRevision(), client.getBranches(false, NULL_PROGRESS_MONITOR).get("master").getId());
668
    }
623
}
669
}

Return to bug 215636