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 227348
Collapse All | Expand All

(-)a/libs.git/apichanges.xml (+19 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 support comparing trees of arbitrary commits</summary>
115
            <version major="1" minor="9"/>
116
            <date day="12" month="3" year="2013"/>
117
            <author login="ovrabec"/>
118
            <compatibility addition="yes"/>
119
            <description>
120
                <ul>
121
                    <li>Adding a new method GitClient.getStatus(File[], String, ProgressMonitor)
122
                    allowing an API client to get statuses of local files not just against the HEAD but against
123
                    an arbitrary commit.</li>
124
                    <li>Adding a new method GitClient.getStatus(File[], String, String, ProgressMonitor)
125
                    allowing an API client to get modifications from the Git history. It is similar to
126
                    GitRevisionInfo.getModifications but returns file statuses between two arbitrary commits
127
                    and not just a commit and its parent.</li>
128
                </ul>
129
            </description>
130
        </change>
131
        <change>
132
            <api name="gitlibrary_api"/>
114
            <summary>Adding support for rebase to the API</summary>
133
            <summary>Adding support for rebase to the API</summary>
115
            <version major="1" minor="8"/>
134
            <version major="1" minor="8"/>
116
            <date day="11" month="3" year="2013"/>
135
            <date day="11" month="3" year="2013"/>
(-)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.8
4
OpenIDE-Module-Specification-Version: 1.9
(-)a/libs.git/src/org/netbeans/libs/git/GitClassFactoryImpl.java (+6 lines)
Lines 60-65 Link Here
60
import org.eclipse.jgit.transport.URIish;
60
import org.eclipse.jgit.transport.URIish;
61
import org.netbeans.libs.git.GitConflictDescriptor.Type;
61
import org.netbeans.libs.git.GitConflictDescriptor.Type;
62
import org.netbeans.libs.git.GitRevertResult.Status;
62
import org.netbeans.libs.git.GitRevertResult.Status;
63
import org.netbeans.libs.git.GitRevisionInfo.GitFileInfo;
63
import org.netbeans.libs.git.jgit.GitClassFactory;
64
import org.netbeans.libs.git.jgit.GitClassFactory;
64
65
65
/**
66
/**
Lines 92-97 Link Here
92
    }
93
    }
93
94
94
    @Override
95
    @Override
96
    public GitFileInfo createFileInfo (File file, String oldPath, GitFileInfo.Status status, File originalFile, String originalPath) {
97
        return new GitFileInfo(file, oldPath, status, originalFile, originalPath);
98
    }
99
100
    @Override
95
    public GitMergeResult createMergeResult (MergeResult mergeResult, File workTree) {
101
    public GitMergeResult createMergeResult (MergeResult mergeResult, File workTree) {
96
        return new GitMergeResult(mergeResult, workTree);
102
        return new GitMergeResult(mergeResult, workTree);
97
    }
103
    }
(-)a/libs.git/src/org/netbeans/libs/git/GitClient.java (-2 / +42 lines)
Lines 49-57 Link Here
49
import java.util.List;
49
import java.util.List;
50
import java.util.Map;
50
import java.util.Map;
51
import java.util.Set;
51
import java.util.Set;
52
import org.eclipse.jgit.lib.Constants;
52
import org.eclipse.jgit.lib.PersonIdent;
53
import org.eclipse.jgit.lib.PersonIdent;
53
import org.eclipse.jgit.lib.Repository;
54
import org.eclipse.jgit.lib.Repository;
54
import org.eclipse.jgit.lib.RepositoryState;
55
import org.eclipse.jgit.lib.RepositoryState;
56
import org.netbeans.libs.git.GitRevisionInfo.GitFileInfo;
55
import org.netbeans.libs.git.jgit.GitClassFactory;
57
import org.netbeans.libs.git.jgit.GitClassFactory;
56
import org.netbeans.libs.git.jgit.JGitCredentialsProvider;
58
import org.netbeans.libs.git.jgit.JGitCredentialsProvider;
57
import org.netbeans.libs.git.jgit.JGitRepository;
59
import org.netbeans.libs.git.jgit.JGitRepository;
Lines 62-67 Link Here
62
import org.netbeans.libs.git.jgit.commands.CheckoutRevisionCommand;
64
import org.netbeans.libs.git.jgit.commands.CheckoutRevisionCommand;
63
import org.netbeans.libs.git.jgit.commands.CleanCommand;
65
import org.netbeans.libs.git.jgit.commands.CleanCommand;
64
import org.netbeans.libs.git.jgit.commands.CommitCommand;
66
import org.netbeans.libs.git.jgit.commands.CommitCommand;
67
import org.netbeans.libs.git.jgit.commands.CompareCommand;
65
import org.netbeans.libs.git.jgit.commands.ConflictCommand;
68
import org.netbeans.libs.git.jgit.commands.ConflictCommand;
66
import org.netbeans.libs.git.jgit.commands.CopyCommand;
69
import org.netbeans.libs.git.jgit.commands.CopyCommand;
67
import org.netbeans.libs.git.jgit.commands.CreateBranchCommand;
70
import org.netbeans.libs.git.jgit.commands.CreateBranchCommand;
Lines 603-621 Link Here
603
    }
606
    }
604
607
605
    /**
608
    /**
606
     * Returns an array of statuses for files under given roots
609
     * Compares the working tree with the current HEAD and returns an array of
610
     * statuses for files under given roots
611
     *
607
     * @param roots root folders or files to search under
612
     * @param roots root folders or files to search under
608
     * @return status array
613
     * @return status array
609
     * @throws GitException an unexpected error occurs
614
     * @throws GitException an unexpected error occurs
610
     */
615
     */
611
    public Map<File, GitStatus> getStatus (File[] roots, ProgressMonitor monitor) throws GitException {
616
    public Map<File, GitStatus> getStatus (File[] roots, ProgressMonitor monitor) throws GitException {
617
        return getStatus(roots, Constants.HEAD, monitor);
618
    }
619
620
    /**
621
     * Compares working tree with a given revision and returns an array of
622
     * statuses for files under given roots
623
     *
624
     * @param roots root folders or files to search under
625
     * @param revision revision to compare with the working tree. If set
626
     * to <code>null</code> HEAD will be used instead.
627
     * @return status array
628
     * @throws GitException an unexpected error occurs
629
     * @since 1.9
630
     */
631
    public Map<File, GitStatus> getStatus (File[] roots, String revision, ProgressMonitor monitor) throws GitException {
612
        Repository repository = gitRepository.getRepository();
632
        Repository repository = gitRepository.getRepository();
613
        StatusCommand cmd = new StatusCommand(repository, getClassFactory(), roots, monitor, delegateListener);
633
        StatusCommand cmd = new StatusCommand(repository, revision == null ? Constants.HEAD : revision,
634
                roots, getClassFactory(), monitor, delegateListener);
614
        cmd.execute();
635
        cmd.execute();
615
        return cmd.getStatuses();
636
        return cmd.getStatuses();
616
    }
637
    }
617
638
618
    /**
639
    /**
640
     * Compares two different commit trees and returns an array of file
641
     * modifications between <code>revisionFirst</code> and <code>revisionSecond</code>
642
     *
643
     * @param roots root folders or files to search under
644
     * @param revisionFirst first revision to compare
645
     * @param revisionSecond second revision to compare
646
     * @return status array
647
     * @throws GitException an unexpected error occurs
648
     * @since 1.9
649
     */
650
    public Map<File, GitFileInfo> getStatus (File[] roots, String revisionFirst, String revisionSecond, ProgressMonitor monitor) throws GitException {
651
        Repository repository = gitRepository.getRepository();
652
        CompareCommand cmd = new CompareCommand(repository, revisionFirst, revisionSecond, roots,
653
                getClassFactory(), monitor);
654
        cmd.execute();
655
        return cmd.getFileDifferences();
656
    }
657
658
    /**
619
     * Returns remote configuration set up for this repository identified by a given remoteName
659
     * Returns remote configuration set up for this repository identified by a given remoteName
620
     * @param remoteName name under which the remote is stored in repository's config file
660
     * @param remoteName name under which the remote is stored in repository's config file
621
     * @param monitor progress monitor
661
     * @param monitor progress monitor
(-)a/libs.git/src/org/netbeans/libs/git/GitRevisionInfo.java (-48 / +4 lines)
Lines 50-57 Link Here
50
import java.util.List;
50
import java.util.List;
51
import java.util.Map;
51
import java.util.Map;
52
import java.util.logging.Logger;
52
import java.util.logging.Logger;
53
import org.eclipse.jgit.diff.DiffEntry;
54
import org.eclipse.jgit.diff.RenameDetector;
55
import org.eclipse.jgit.lib.ObjectId;
53
import org.eclipse.jgit.lib.ObjectId;
56
import org.eclipse.jgit.lib.PersonIdent;
54
import org.eclipse.jgit.lib.PersonIdent;
57
import org.eclipse.jgit.lib.Repository;
55
import org.eclipse.jgit.lib.Repository;
Lines 62-67 Link Here
62
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
60
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
63
import org.eclipse.jgit.treewalk.filter.PathFilter;
61
import org.eclipse.jgit.treewalk.filter.PathFilter;
64
import org.eclipse.jgit.treewalk.filter.TreeFilter;
62
import org.eclipse.jgit.treewalk.filter.TreeFilter;
63
import org.netbeans.libs.git.jgit.Utils;
65
64
66
/**
65
/**
67
 * Provides information about a certain commit, usually is returned by 
66
 * Provides information about a certain commit, usually is returned by 
Lines 164-170 Link Here
164
        RevWalk revWalk = new RevWalk(repository);
163
        RevWalk revWalk = new RevWalk(repository);
165
        TreeWalk walk = new TreeWalk(repository);
164
        TreeWalk walk = new TreeWalk(repository);
166
        try {
165
        try {
167
            ArrayList<GitFileInfo> result = new ArrayList<GitFileInfo>();
166
            List<GitFileInfo> result;
168
            walk.reset();
167
            walk.reset();
169
            walk.setRecursive(true);
168
            walk.setRecursive(true);
170
            RevCommit parentCommit = null;
169
            RevCommit parentCommit = null;
Lines 184-235 Link Here
184
            walk.addTree(revCommit.getTree().getId());
183
            walk.addTree(revCommit.getTree().getId());
185
            walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilter.ANY_DIFF));
184
            walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilter.ANY_DIFF));
186
            if (parentCommit != null) {
185
            if (parentCommit != null) {
187
                List<DiffEntry> entries = DiffEntry.scan(walk);
186
                result = Utils.getDiffEntries(repository, walk, GitClassFactoryImpl.getInstance());
188
                RenameDetector rd = new RenameDetector(repository);
189
                rd.addAll(entries);
190
                entries = rd.compute();
191
                for (DiffEntry e : entries) {
192
                    GitFileInfo.Status status;
193
                    File oldFile = null;
194
                    String oldPath = null;
195
                    String path = e.getOldPath();
196
                    if (path == null) {
197
                        path = e.getNewPath();
198
                    }
199
                    switch (e.getChangeType()) {
200
                        case ADD:
201
                            status = GitFileInfo.Status.ADDED;
202
                            path = e.getNewPath();
203
                            break;
204
                        case COPY:
205
                            status = GitFileInfo.Status.COPIED;
206
                            oldFile = new File(repository.getWorkTree(), e.getOldPath());
207
                            oldPath = e.getOldPath();
208
                            path = e.getNewPath();
209
                            break;
210
                        case DELETE:
211
                            status = GitFileInfo.Status.REMOVED;
212
                            path = e.getOldPath();
213
                            break;
214
                        case MODIFY:
215
                            status = GitFileInfo.Status.MODIFIED;
216
                            path = e.getOldPath();
217
                            break;
218
                        case RENAME:
219
                            status = GitFileInfo.Status.RENAMED;
220
                            oldFile = new File(repository.getWorkTree(), e.getOldPath());
221
                            oldPath = e.getOldPath();
222
                            path = e.getNewPath();
223
                            break;
224
                        default:
225
                            status = GitFileInfo.Status.UNKNOWN;
226
                    }
227
                    if (status == GitFileInfo.Status.RENAMED) {
228
                        result.add(new GitFileInfo(new File(repository.getWorkTree(), e.getOldPath()), e.getOldPath(), GitFileInfo.Status.REMOVED, null, null));
229
                    }
230
                    result.add(new GitFileInfo(new File(repository.getWorkTree(), path), path, status, oldFile, oldPath));
231
                }
232
            } else {
187
            } else {
188
                result = new ArrayList<GitFileInfo>();
233
                while (walk.next()) {
189
                while (walk.next()) {
234
                    result.add(new GitFileInfo(new File(repository.getWorkTree(), walk.getPathString()), walk.getPathString(), GitFileInfo.Status.ADDED, null, null));
190
                    result.add(new GitFileInfo(new File(repository.getWorkTree(), walk.getPathString()), walk.getPathString(), GitFileInfo.Status.ADDED, null, null));
235
                }
191
                }
(-)a/libs.git/src/org/netbeans/libs/git/jgit/GitClassFactory.java (+3 lines)
Lines 69-74 Link Here
69
import org.netbeans.libs.git.GitRemoteConfig;
69
import org.netbeans.libs.git.GitRemoteConfig;
70
import org.netbeans.libs.git.GitRevertResult;
70
import org.netbeans.libs.git.GitRevertResult;
71
import org.netbeans.libs.git.GitRevisionInfo;
71
import org.netbeans.libs.git.GitRevisionInfo;
72
import org.netbeans.libs.git.GitRevisionInfo.GitFileInfo;
72
import org.netbeans.libs.git.GitStatus;
73
import org.netbeans.libs.git.GitStatus;
73
import org.netbeans.libs.git.GitStatus.Status;
74
import org.netbeans.libs.git.GitStatus.Status;
74
import org.netbeans.libs.git.GitTag;
75
import org.netbeans.libs.git.GitTag;
Lines 86-91 Link Here
86
    public abstract GitBranch createBranch (String name, boolean remote, boolean active, ObjectId id);
87
    public abstract GitBranch createBranch (String name, boolean remote, boolean active, ObjectId id);
87
88
88
    public abstract GitConflictDescriptor createConflictDescriptor (Type type);
89
    public abstract GitConflictDescriptor createConflictDescriptor (Type type);
90
91
    public abstract GitFileInfo createFileInfo (File file, String oldPath, GitFileInfo.Status status, File originalFile, String originalPath);
89
    
92
    
90
    public abstract GitMergeResult createMergeResult (MergeResult mergeResult, File workTree);
93
    public abstract GitMergeResult createMergeResult (MergeResult mergeResult, File workTree);
91
94
(-)a/libs.git/src/org/netbeans/libs/git/jgit/Utils.java (+54 lines)
Lines 55-60 Link Here
55
import java.util.ResourceBundle;
55
import java.util.ResourceBundle;
56
import java.util.logging.Level;
56
import java.util.logging.Level;
57
import java.util.logging.Logger;
57
import java.util.logging.Logger;
58
import org.eclipse.jgit.diff.DiffEntry;
59
import org.eclipse.jgit.diff.RenameDetector;
58
import org.eclipse.jgit.errors.AmbiguousObjectException;
60
import org.eclipse.jgit.errors.AmbiguousObjectException;
59
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
61
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
60
import org.eclipse.jgit.errors.MissingObjectException;
62
import org.eclipse.jgit.errors.MissingObjectException;
Lines 79-84 Link Here
79
import org.netbeans.libs.git.GitBranch;
81
import org.netbeans.libs.git.GitBranch;
80
import org.netbeans.libs.git.GitException;
82
import org.netbeans.libs.git.GitException;
81
import org.netbeans.libs.git.GitObjectType;
83
import org.netbeans.libs.git.GitObjectType;
84
import org.netbeans.libs.git.GitRevisionInfo;
85
import org.netbeans.libs.git.GitRevisionInfo.GitFileInfo;
82
86
83
/**
87
/**
84
 *
88
 *
Lines 119-124 Link Here
119
        return filter;
123
        return filter;
120
    }
124
    }
121
125
126
    public static List<GitFileInfo> getDiffEntries (Repository repository, TreeWalk walk, GitClassFactory fac) throws IOException {
127
        List<GitFileInfo> result = new ArrayList<GitFileInfo>();
128
        List<DiffEntry> entries = DiffEntry.scan(walk);
129
        RenameDetector rd = new RenameDetector(repository);
130
        rd.addAll(entries);
131
        entries = rd.compute();
132
        for (DiffEntry e : entries) {
133
            GitRevisionInfo.GitFileInfo.Status status;
134
            File oldFile = null;
135
            String oldPath = null;
136
            String path = e.getOldPath();
137
            if (path == null) {
138
                path = e.getNewPath();
139
            }
140
            switch (e.getChangeType()) {
141
                case ADD:
142
                    status = GitRevisionInfo.GitFileInfo.Status.ADDED;
143
                    path = e.getNewPath();
144
                    break;
145
                case COPY:
146
                    status = GitRevisionInfo.GitFileInfo.Status.COPIED;
147
                    oldFile = new File(repository.getWorkTree(), e.getOldPath());
148
                    oldPath = e.getOldPath();
149
                    path = e.getNewPath();
150
                    break;
151
                case DELETE:
152
                    status = GitRevisionInfo.GitFileInfo.Status.REMOVED;
153
                    path = e.getOldPath();
154
                    break;
155
                case MODIFY:
156
                    status = GitRevisionInfo.GitFileInfo.Status.MODIFIED;
157
                    path = e.getOldPath();
158
                    break;
159
                case RENAME:
160
                    status = GitRevisionInfo.GitFileInfo.Status.RENAMED;
161
                    oldFile = new File(repository.getWorkTree(), e.getOldPath());
162
                    oldPath = e.getOldPath();
163
                    path = e.getNewPath();
164
                    break;
165
                default:
166
                    status = GitRevisionInfo.GitFileInfo.Status.UNKNOWN;
167
            }
168
            if (status == GitRevisionInfo.GitFileInfo.Status.RENAMED) {
169
                result.add(fac.createFileInfo(new File(repository.getWorkTree(), e.getOldPath()), e.getOldPath(), GitRevisionInfo.GitFileInfo.Status.REMOVED, null, null));
170
            }
171
            result.add(fac.createFileInfo(new File(repository.getWorkTree(), path), path, status, oldFile, oldPath));
172
        }
173
        return result;
174
    }
175
122
    private static Collection<PathFilter> getPathFilters (Collection<String> relativePaths) {
176
    private static Collection<PathFilter> getPathFilters (Collection<String> relativePaths) {
123
        Collection<PathFilter> filters = new LinkedList<PathFilter>();
177
        Collection<PathFilter> filters = new LinkedList<PathFilter>();
124
        for (String path : relativePaths) {
178
        for (String path : relativePaths) {
(-)236d21a95856 (+130 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.libs.git.jgit.commands;
44
45
import java.io.File;
46
import java.io.IOException;
47
import java.util.Collection;
48
import java.util.LinkedHashMap;
49
import java.util.List;
50
import java.util.Map;
51
import org.eclipse.jgit.lib.Repository;
52
import org.eclipse.jgit.treewalk.*;
53
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
54
import org.eclipse.jgit.treewalk.filter.PathFilter;
55
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
56
import org.eclipse.jgit.treewalk.filter.TreeFilter;
57
import org.netbeans.libs.git.GitException;
58
import org.netbeans.libs.git.GitRevisionInfo;
59
import org.netbeans.libs.git.jgit.GitClassFactory;
60
import org.netbeans.libs.git.jgit.Utils;
61
import org.netbeans.libs.git.progress.ProgressMonitor;
62
63
/**
64
 *
65
 * @author ondra
66
 */
67
public class CompareCommand extends GitCommand {
68
    private final LinkedHashMap<File, GitRevisionInfo.GitFileInfo> statuses;
69
    private final File[] roots;
70
    private final String revisionFirst;
71
    private final String revisionSecond;
72
73
    public CompareCommand (Repository repository, String revisionFirst, String revisionSecond, File[] roots,
74
            GitClassFactory gitFactory, ProgressMonitor monitor) {
75
        super(repository, gitFactory, monitor);
76
        this.roots = roots;
77
        this.revisionFirst = revisionFirst;
78
        this.revisionSecond = revisionSecond;
79
        statuses = new LinkedHashMap<File, GitRevisionInfo.GitFileInfo>();
80
    }
81
82
    @Override
83
    protected String getCommandDescription () {
84
        StringBuilder sb = new StringBuilder("git diff --raw"); //NOI18N
85
        sb.append(revisionFirst).append(' ').append(revisionSecond);                
86
        for (File root : roots) {
87
            sb.append(" ").append(root.getAbsolutePath());
88
        }
89
        return sb.toString();
90
    }
91
92
    @Override
93
    protected boolean prepareCommand () throws GitException {
94
        return getRepository().getDirectory().exists();
95
    }
96
97
    @Override
98
    protected void run () throws GitException {
99
        Repository repository = getRepository();
100
        TreeWalk walk = new TreeWalk(repository);
101
        try {
102
            walk.reset();
103
            walk.setRecursive(true);
104
            walk.addTree(Utils.findCommit(repository, revisionFirst).getTree());
105
            walk.addTree(Utils.findCommit(repository, revisionSecond).getTree());
106
            Collection<PathFilter> pathFilters = Utils.getPathFilters(repository.getWorkTree(), roots);
107
            if (pathFilters.isEmpty()) {
108
                walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilter.ANY_DIFF));
109
            } else {
110
                walk.setFilter(AndTreeFilter.create(new TreeFilter[] { 
111
                    TreeFilter.ANY_DIFF,
112
                    PathFilter.ANY_DIFF,
113
                    PathFilterGroup.create(pathFilters)
114
                }));
115
            }
116
            List<GitRevisionInfo.GitFileInfo> infos = Utils.getDiffEntries(repository, walk, getClassFactory());
117
            for (GitRevisionInfo.GitFileInfo info : infos) {
118
                statuses.put(info.getFile(), info);
119
            }
120
        } catch (IOException ex) {
121
            throw new GitException(ex);
122
        } finally {
123
            walk.release();
124
        }
125
    }
126
127
    public Map<File, GitRevisionInfo.GitFileInfo> getFileDifferences () {
128
        return statuses;
129
    }
130
}
(-)a/libs.git/src/org/netbeans/libs/git/jgit/commands/ConflictCommand.java (-1 / +2 lines)
Lines 49-54 Link Here
49
import org.eclipse.jgit.dircache.DirCacheEntry;
49
import org.eclipse.jgit.dircache.DirCacheEntry;
50
import org.eclipse.jgit.dircache.DirCacheIterator;
50
import org.eclipse.jgit.dircache.DirCacheIterator;
51
import org.eclipse.jgit.errors.CorruptObjectException;
51
import org.eclipse.jgit.errors.CorruptObjectException;
52
import org.eclipse.jgit.lib.Constants;
52
import org.eclipse.jgit.lib.Repository;
53
import org.eclipse.jgit.lib.Repository;
53
import org.eclipse.jgit.treewalk.TreeWalk;
54
import org.eclipse.jgit.treewalk.TreeWalk;
54
import org.eclipse.jgit.treewalk.filter.PathFilter;
55
import org.eclipse.jgit.treewalk.filter.PathFilter;
Lines 72-78 Link Here
72
    private final File[] roots;
73
    private final File[] roots;
73
74
74
    public ConflictCommand (Repository repository, GitClassFactory gitFactory, File[] roots, ProgressMonitor monitor, StatusListener listener) {
75
    public ConflictCommand (Repository repository, GitClassFactory gitFactory, File[] roots, ProgressMonitor monitor, StatusListener listener) {
75
        super(repository, gitFactory, roots, monitor, listener);
76
        super(repository, Constants.HEAD, roots, gitFactory, monitor, listener);
76
        this.monitor = monitor;
77
        this.monitor = monitor;
77
        this.listener = listener;
78
        this.listener = listener;
78
        this.roots = roots;
79
        this.roots = roots;
(-)a/libs.git/src/org/netbeans/libs/git/jgit/commands/RebaseCommand.java (-2 / +2 lines)
Lines 162-169 Link Here
162
            Repository repository = getRepository();
162
            Repository repository = getRepository();
163
            GitRevisionInfo info = getClassFactory().createRevisionInfo(currentCommit, repository);
163
            GitRevisionInfo info = getClassFactory().createRevisionInfo(currentCommit, repository);
164
            Map<File, GitRevisionInfo.GitFileInfo> modifiedFiles = info.getModifiedFiles();
164
            Map<File, GitRevisionInfo.GitFileInfo> modifiedFiles = info.getModifiedFiles();
165
            StatusCommand cmd = new StatusCommand(repository, getClassFactory(), modifiedFiles.keySet().toArray(
165
            StatusCommand cmd = new StatusCommand(repository, Constants.HEAD, modifiedFiles.keySet().toArray(
166
                    new File[modifiedFiles.keySet().size()]),
166
                    new File[modifiedFiles.keySet().size()]), getClassFactory(), 
167
                    new DelegatingGitProgressMonitor(monitor),
167
                    new DelegatingGitProgressMonitor(monitor),
168
                    new StatusListener() {
168
                    new StatusListener() {
169
                        @Override
169
                        @Override
(-)a/libs.git/src/org/netbeans/libs/git/jgit/commands/StatusCommand.java (-14 / +21 lines)
Lines 95-113 Link Here
95
    private final File[] roots;
95
    private final File[] roots;
96
    private final ProgressMonitor monitor;
96
    private final ProgressMonitor monitor;
97
    private final StatusListener listener;
97
    private final StatusListener listener;
98
    private final String revision;
98
    private static final String PROP_TRACK_SYMLINKS = "org.netbeans.libs.git.trackSymLinks"; //NOI18N
99
    private static final String PROP_TRACK_SYMLINKS = "org.netbeans.libs.git.trackSymLinks"; //NOI18N
99
100
100
    public StatusCommand (Repository repository, GitClassFactory gitFactory, File[] roots, ProgressMonitor monitor, StatusListener listener) {
101
    public StatusCommand (Repository repository, String revision, File[] roots, GitClassFactory gitFactory,
102
            ProgressMonitor monitor, StatusListener listener) {
101
        super(repository, gitFactory, monitor);
103
        super(repository, gitFactory, monitor);
102
        this.roots = roots;
104
        this.roots = roots;
103
        this.monitor = monitor;
105
        this.monitor = monitor;
104
        this.listener = listener;
106
        this.listener = listener;
107
        this.revision = revision;
105
        statuses = new LinkedHashMap<File, GitStatus>();
108
        statuses = new LinkedHashMap<File, GitStatus>();
106
    }
109
    }
107
110
108
    @Override
111
    @Override
109
    protected String getCommandDescription () {
112
    protected String getCommandDescription () {
110
        StringBuilder sb = new StringBuilder("git status"); //NOI18N
113
        StringBuilder sb = new StringBuilder("git "); //NOI18N
114
        if (Constants.HEAD.equals(revision)) {
115
             sb.append("status"); //NOI18N
116
        } else {
117
             sb.append("diff --raw"); //NOI18N
118
        }
111
        for (File root : roots) {
119
        for (File root : roots) {
112
            sb.append(" ").append(root.getAbsolutePath());
120
            sb.append(" ").append(root.getAbsolutePath());
113
        }
121
        }
Lines 128-143 Link Here
128
            try {
136
            try {
129
                String workTreePath = repository.getWorkTree().getAbsolutePath();
137
                String workTreePath = repository.getWorkTree().getAbsolutePath();
130
                Collection<PathFilter> pathFilters = Utils.getPathFilters(repository.getWorkTree(), roots);
138
                Collection<PathFilter> pathFilters = Utils.getPathFilters(repository.getWorkTree(), roots);
131
                Map<String, DiffEntry> renames = detectRenames(repository, cache);
139
                ObjectId commitId = Utils.parseObjectId(repository, revision);
140
                Map<String, DiffEntry> renames = detectRenames(repository, cache, commitId);
132
                TreeWalk treeWalk = new TreeWalk(repository);
141
                TreeWalk treeWalk = new TreeWalk(repository);
133
                if (!pathFilters.isEmpty()) {
142
                if (!pathFilters.isEmpty()) {
134
                    treeWalk.setFilter(PathFilterGroup.create(pathFilters));
143
                    treeWalk.setFilter(PathFilterGroup.create(pathFilters));
135
                }
144
                }
136
                treeWalk.setRecursive(false);
145
                treeWalk.setRecursive(false);
137
                treeWalk.reset();
146
                treeWalk.reset();
138
                ObjectId headId = repository.resolve(Constants.HEAD);
147
                if (commitId != null) {
139
                if (headId != null) {
148
                    treeWalk.addTree(new RevWalk(repository).parseTree(commitId));
140
                    treeWalk.addTree(new RevWalk(repository).parseTree(headId));
141
                } else {
149
                } else {
142
                    treeWalk.addTree(new EmptyTreeIterator());
150
                    treeWalk.addTree(new EmptyTreeIterator());
143
                }
151
                }
Lines 145-151 Link Here
145
                treeWalk.addTree(new DirCacheIterator(cache));
153
                treeWalk.addTree(new DirCacheIterator(cache));
146
                // Working directory
154
                // Working directory
147
                treeWalk.addTree(new FileTreeIterator(repository));
155
                treeWalk.addTree(new FileTreeIterator(repository));
148
                final int T_HEAD = 0;
156
                final int T_COMMIT = 0;
149
                final int T_INDEX = 1;
157
                final int T_INDEX = 1;
150
                final int T_WORKSPACE = 2;
158
                final int T_WORKSPACE = 2;
151
                String lastPath = null;
159
                String lastPath = null;
Lines 166-172 Link Here
166
                    }
174
                    }
167
                    lastPath = path;
175
                    lastPath = path;
168
                    File file = new File(workTreePath + File.separator + path);
176
                    File file = new File(workTreePath + File.separator + path);
169
                    int mHead = treeWalk.getRawMode(T_HEAD);
177
                    int mHead = treeWalk.getRawMode(T_COMMIT);
170
                    int mIndex = treeWalk.getRawMode(T_INDEX);
178
                    int mIndex = treeWalk.getRawMode(T_INDEX);
171
                    int mWorking = treeWalk.getRawMode(T_WORKSPACE);
179
                    int mWorking = treeWalk.getRawMode(T_WORKSPACE);
172
                    GitStatus.Status statusHeadIndex;
180
                    GitStatus.Status statusHeadIndex;
Lines 177-183 Link Here
177
                        statusHeadIndex = GitStatus.Status.STATUS_ADDED;
185
                        statusHeadIndex = GitStatus.Status.STATUS_ADDED;
178
                    } else if (mIndex == FileMode.MISSING.getBits() && mHead != FileMode.MISSING.getBits()) {
186
                    } else if (mIndex == FileMode.MISSING.getBits() && mHead != FileMode.MISSING.getBits()) {
179
                        statusHeadIndex = GitStatus.Status.STATUS_REMOVED;
187
                        statusHeadIndex = GitStatus.Status.STATUS_REMOVED;
180
                    } else if (mHead != mIndex || (mIndex != FileMode.TREE.getBits() && !treeWalk.idEqual(T_HEAD, T_INDEX))) {
188
                    } else if (mHead != mIndex || (mIndex != FileMode.TREE.getBits() && !treeWalk.idEqual(T_COMMIT, T_INDEX))) {
181
                        statusHeadIndex = GitStatus.Status.STATUS_MODIFIED;
189
                        statusHeadIndex = GitStatus.Status.STATUS_MODIFIED;
182
                    } else {
190
                    } else {
183
                        statusHeadIndex = GitStatus.Status.STATUS_NORMAL;
191
                        statusHeadIndex = GitStatus.Status.STATUS_NORMAL;
Lines 234-240 Link Here
234
                                    && (indexEntry == null || !indexEntry.isAssumeValid()) //no update-index --assume-unchanged
242
                                    && (indexEntry == null || !indexEntry.isAssumeValid()) //no update-index --assume-unchanged
235
                                    // head vs wt can be modified only when head vs index or index vs wt are modified, otherwise it's probably line-endings issue
243
                                    // head vs wt can be modified only when head vs index or index vs wt are modified, otherwise it's probably line-endings issue
236
                                    && (statusIndexWC != GitStatus.Status.STATUS_NORMAL || statusHeadIndex != GitStatus.Status.STATUS_NORMAL)
244
                                    && (statusIndexWC != GitStatus.Status.STATUS_NORMAL || statusHeadIndex != GitStatus.Status.STATUS_NORMAL)
237
                                    && !treeWalk.getObjectId(T_HEAD).equals(fti.getEntryObjectId())))) {
245
                                    && !treeWalk.getObjectId(T_COMMIT).equals(fti.getEntryObjectId())))) {
238
                            statusHeadWC = GitStatus.Status.STATUS_MODIFIED;
246
                            statusHeadWC = GitStatus.Status.STATUS_MODIFIED;
239
                        } else {
247
                        } else {
240
                            statusHeadWC = GitStatus.Status.STATUS_NORMAL;
248
                            statusHeadWC = GitStatus.Status.STATUS_NORMAL;
Lines 271-285 Link Here
271
        return statuses;
279
        return statuses;
272
    }
280
    }
273
281
274
    private Map<String, DiffEntry> detectRenames (Repository repository, DirCache cache) {
282
    private Map<String, DiffEntry> detectRenames (Repository repository, DirCache cache, ObjectId commitId) {
275
        List<DiffEntry> entries;
283
        List<DiffEntry> entries;
276
        TreeWalk treeWalk = new TreeWalk(repository);
284
        TreeWalk treeWalk = new TreeWalk(repository);
277
        try {
285
        try {
278
            treeWalk.setRecursive(true);
286
            treeWalk.setRecursive(true);
279
            treeWalk.reset();
287
            treeWalk.reset();
280
            ObjectId headId = repository.resolve(Constants.HEAD);
288
            if (commitId != null) {
281
            if (headId != null) {
289
                treeWalk.addTree(new RevWalk(repository).parseTree(commitId));
282
                treeWalk.addTree(new RevWalk(repository).parseTree(headId));
283
            } else {
290
            } else {
284
                treeWalk.addTree(new EmptyTreeIterator());
291
                treeWalk.addTree(new EmptyTreeIterator());
285
            }
292
            }
(-)a/libs.git/test/unit/src/org/netbeans/libs/git/jgit/CommandsTestSuite.java (+2 lines)
Lines 53-58 Link Here
53
import org.netbeans.libs.git.jgit.commands.CheckoutTest;
53
import org.netbeans.libs.git.jgit.commands.CheckoutTest;
54
import org.netbeans.libs.git.jgit.commands.CleanTest;
54
import org.netbeans.libs.git.jgit.commands.CleanTest;
55
import org.netbeans.libs.git.jgit.commands.CommitTest;
55
import org.netbeans.libs.git.jgit.commands.CommitTest;
56
import org.netbeans.libs.git.jgit.commands.CompareCommitTest;
56
import org.netbeans.libs.git.jgit.commands.CopyTest;
57
import org.netbeans.libs.git.jgit.commands.CopyTest;
57
import org.netbeans.libs.git.jgit.commands.ExportCommitTest;
58
import org.netbeans.libs.git.jgit.commands.ExportCommitTest;
58
import org.netbeans.libs.git.jgit.commands.ExportDiffTest;
59
import org.netbeans.libs.git.jgit.commands.ExportDiffTest;
Lines 97-102 Link Here
97
        suite.addTestSuite(CheckoutTest.class);
98
        suite.addTestSuite(CheckoutTest.class);
98
        suite.addTestSuite(CleanTest.class);
99
        suite.addTestSuite(CleanTest.class);
99
        suite.addTestSuite(CommitTest.class);
100
        suite.addTestSuite(CommitTest.class);
101
        suite.addTestSuite(CompareCommitTest.class);
100
        suite.addTestSuite(CopyTest.class);
102
        suite.addTestSuite(CopyTest.class);
101
        suite.addTestSuite(ExportCommitTest.class);
103
        suite.addTestSuite(ExportCommitTest.class);
102
        suite.addTestSuite(ExportDiffTest.class);
104
        suite.addTestSuite(ExportDiffTest.class);
(-)236d21a95856 (+181 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.libs.git.jgit.commands;
44
45
import java.io.File;
46
import java.io.IOException;
47
import java.util.Map;
48
import static junit.framework.Assert.assertEquals;
49
import org.eclipse.jgit.lib.Constants;
50
import org.eclipse.jgit.lib.Repository;
51
import org.netbeans.libs.git.GitClient;
52
import org.netbeans.libs.git.GitRevisionInfo;
53
import org.netbeans.libs.git.GitRevisionInfo.GitFileInfo.Status;
54
import org.netbeans.libs.git.jgit.AbstractGitTestCase;
55
56
/**
57
 *
58
 * @author ondra
59
 */
60
public class CompareCommitTest extends AbstractGitTestCase {
61
    private Repository repository;
62
    private File workDir;
63
64
    public CompareCommitTest (String testName) throws IOException {
65
        super(testName);
66
    }
67
68
    @Override
69
    protected void setUp() throws Exception {
70
        super.setUp();
71
        workDir = getWorkingDirectory();
72
        repository = getRepository(getLocalGitRepository());
73
    }
74
    
75
    public void testCompareSimple () throws Exception {
76
        File file = new File(workDir, "file");
77
        File[] files = new File[] { file };
78
        write(file, "init\n");
79
        add(files);
80
        commit(files);
81
        
82
        GitClient client = getClient(workDir);
83
        String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId();
84
        write(file, "modification\n");
85
        add(files);
86
        GitRevisionInfo revision2 = client.commit(files, "my commit message", null, null, NULL_PROGRESS_MONITOR);
87
        Map<File, GitRevisionInfo.GitFileInfo> statuses = client.getStatus(files, Constants.HEAD, revision1, NULL_PROGRESS_MONITOR);
88
        assertEquals(1, statuses.size());
89
        assertEquals(Status.MODIFIED, statuses.get(file).getStatus());
90
        
91
        write(file, "modification 2\n");
92
        add(files);
93
        GitRevisionInfo revision3 = client.commit(files, "my commit 3 message", null, null, NULL_PROGRESS_MONITOR);
94
        statuses = client.getStatus(files, revision1, Constants.HEAD, NULL_PROGRESS_MONITOR);
95
        assertEquals(1, statuses.size());
96
        assertEquals(Status.MODIFIED, statuses.get(file).getStatus());
97
        
98
        statuses = client.getStatus(files, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR);
99
        assertEquals(1, statuses.size());
100
        assertEquals(Status.MODIFIED, statuses.get(file).getStatus());
101
        
102
        statuses = client.getStatus(files, revision2.getRevision(), revision3.getRevision(), NULL_PROGRESS_MONITOR);
103
        assertEquals(1, statuses.size());
104
        assertEquals(Status.MODIFIED, statuses.get(file).getStatus());
105
    }
106
    
107
    public void testCompareRevertModification () throws Exception {
108
        File file = new File(workDir, "file");
109
        File[] files = new File[] { file };
110
        write(file, "init\n");
111
        add(files);
112
        commit(files);
113
        
114
        GitClient client = getClient(workDir);
115
        String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId();
116
        write(file, "modification\n");
117
        add(files);
118
        GitRevisionInfo revision2 = client.commit(files, "my commit message", null, null, NULL_PROGRESS_MONITOR);
119
        
120
        write(file, "init\n");
121
        add(files);
122
        GitRevisionInfo revision3 = client.commit(files, "my commit 3 message", null, null, NULL_PROGRESS_MONITOR);
123
        Map<File, GitRevisionInfo.GitFileInfo> statuses = client.getStatus(files, revision1, Constants.HEAD, NULL_PROGRESS_MONITOR);
124
        assertTrue(statuses.isEmpty());
125
    }
126
    
127
    public void testCompareSelection () throws Exception {
128
        File file = new File(workDir, "file");
129
        File file2 = new File(workDir, "file2");
130
        File[] files = new File[] { file, file2 };
131
        write(file, "init\n");
132
        add(files);
133
        commit(files);
134
        
135
        GitClient client = getClient(workDir);
136
        String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId();
137
        write(file, "modification\n");
138
        add(files);
139
        GitRevisionInfo revision2 = client.commit(files, "my commit message", null, null, NULL_PROGRESS_MONITOR);
140
        
141
        write(file2, "adding file 2\n");
142
        add(files);
143
        GitRevisionInfo revision3 = client.commit(files, "adding file 2", null, null, NULL_PROGRESS_MONITOR);
144
        Map<File, GitRevisionInfo.GitFileInfo> statuses = client.getStatus(new File[] { file }, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR);
145
        assertEquals(1, statuses.size());
146
        assertEquals(Status.MODIFIED, statuses.get(file).getStatus());
147
        
148
        statuses = client.getStatus(new File[] { file2 }, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR);
149
        assertEquals(1, statuses.size());
150
        assertEquals(Status.ADDED, statuses.get(file2).getStatus());
151
        
152
        statuses = client.getStatus(files, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR);
153
        assertEquals(2, statuses.size());
154
        assertEquals(Status.MODIFIED, statuses.get(file).getStatus());
155
        assertEquals(Status.ADDED, statuses.get(file2).getStatus());
156
    }
157
    
158
    public void testCompareRename () throws Exception {
159
        File file = new File(workDir, "file");
160
        File file2 = new File(workDir, "file2");
161
        File[] files = new File[] { file, file2 };
162
        write(file, "files content\n");
163
        add(files);
164
        commit(files);
165
        
166
        GitClient client = getClient(workDir);
167
        String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId();
168
        remove(false, file);
169
        
170
        client.commit(files, "removing file", null, null, NULL_PROGRESS_MONITOR);
171
        
172
        write(file2, "files content\n");
173
        add(files);
174
        GitRevisionInfo revision3 = client.commit(files, "adding file as file2", null, null, NULL_PROGRESS_MONITOR);
175
        Map<File, GitRevisionInfo.GitFileInfo> statuses = client.getStatus(files, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR);
176
        assertEquals(2, statuses.size());
177
        assertEquals(Status.REMOVED, statuses.get(file).getStatus());
178
        assertEquals(Status.RENAMED, statuses.get(file2).getStatus());
179
        assertEquals(file, statuses.get(file2).getOriginalFile());
180
    }
181
}
(-)a/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/StatusTest.java (-1 / +116 lines)
Lines 45-55 Link Here
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.util.HashMap;
46
import java.util.HashMap;
47
import java.util.Map;
47
import java.util.Map;
48
import org.eclipse.jgit.api.Git;
48
import static junit.framework.Assert.assertFalse;
49
import org.eclipse.jgit.dircache.DirCache;
49
import org.eclipse.jgit.dircache.DirCache;
50
import org.eclipse.jgit.dircache.DirCacheBuilder;
50
import org.eclipse.jgit.dircache.DirCacheBuilder;
51
import org.eclipse.jgit.dircache.DirCacheEntry;
51
import org.eclipse.jgit.dircache.DirCacheEntry;
52
import org.eclipse.jgit.lib.ConfigConstants;
52
import org.eclipse.jgit.lib.ConfigConstants;
53
import org.eclipse.jgit.lib.Constants;
53
import org.eclipse.jgit.lib.Repository;
54
import org.eclipse.jgit.lib.Repository;
54
import org.eclipse.jgit.lib.StoredConfig;
55
import org.eclipse.jgit.lib.StoredConfig;
55
import org.netbeans.libs.git.GitClient;
56
import org.netbeans.libs.git.GitClient;
Lines 166-171 Link Here
166
        // what about isIgnored() here?
167
        // what about isIgnored() here?
167
        assertStatus(statuses, workDir, ignored, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false, listener);
168
        assertStatus(statuses, workDir, ignored, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false, listener);
168
    }
169
    }
170
    
171
    // diff WT against a commit other than HEAD
172
    public void testMiscStatusCommit () throws Exception {
173
        write(new File(workDir, ".gitignore"), "ignored");
174
        File untracked = new File(workDir, "untracked");
175
        write(untracked, "untracked");
176
        File ignored = new File(workDir, "ignored");
177
        write(ignored, "ignored");
178
        File added_uptodate = new File(workDir, "added-uptodate");
179
        write(added_uptodate, "added-uptodate");
180
        File added_modified = new File(workDir, "added-modified");
181
        write(added_modified, "added_modified");
182
        File added_deleted = new File(workDir, "added-deleted");
183
        write(added_deleted, "added_deleted");
184
185
        File uptodate_uptodate = new File(workDir, "uptodate-uptodate");
186
        write(uptodate_uptodate, "uptodate_uptodate");
187
        File uptodate_modified = new File(workDir, "uptodate-modified");
188
        write(uptodate_modified, "uptodate_modified");
189
        File uptodate_deleted = new File(workDir, "uptodate-deleted");
190
        write(uptodate_deleted, "uptodate_deleted");
191
192
        File modified_uptodate = new File(workDir, "modified-uptodate");
193
        write(modified_uptodate, "modified_uptodate");
194
        File modified_modified = new File(workDir, "modified-modified");
195
        write(modified_modified, "modified_modified");
196
        File modified_reset = new File(workDir, "modified-reset");
197
        write(modified_reset, "modified_reset");
198
        File modified_deleted = new File(workDir, "modified-deleted");
199
        write(modified_deleted, "modified_deleted");
200
201
        // we cannot
202
        File deleted_uptodate = new File(workDir, "deleted-uptodate");
203
        write(deleted_uptodate, "deleted_uptodate");
204
        File deleted_untracked = new File(workDir, "deleted-untracked");
205
        write(deleted_untracked, "deleted_untracked");
206
        File deleted_modified = new File(workDir, "deleted-modified");
207
        write(deleted_modified, "deleted_modified");
208
209
        add(uptodate_uptodate, uptodate_modified, uptodate_deleted, modified_uptodate, modified_modified, modified_reset, modified_deleted, deleted_uptodate, deleted_untracked, deleted_modified);
210
        commit(workDir);
211
        add(added_uptodate, added_modified, added_deleted);
212
        write(modified_deleted, "modification modified_deleted");
213
        write(modified_modified, "modification modified_modified");
214
        write(modified_reset, "modification modified_reset");
215
        write(modified_uptodate, "modification modified_uptodate");
216
        add(modified_deleted, modified_modified, modified_reset, modified_uptodate);
217
        deleted_uptodate.delete();
218
        deleted_untracked.delete();
219
        deleted_modified.delete();
220
        remove(true, deleted_uptodate, deleted_untracked, deleted_modified);
221
        write(added_modified, "modification2 added_modified");
222
        write(uptodate_modified, "modification2 uptodate_modified");
223
        write(modified_modified, "modification2 modified_modified");
224
        write(modified_reset, "modified_reset");
225
        added_deleted.delete();
226
        modified_deleted.delete();
227
        uptodate_deleted.delete();
228
        write(deleted_untracked, "deleted_untracked");
229
        write(deleted_modified, "deleted_modified\nchange");
230
        
231
        GitClient client = getClient(workDir);
232
        String revId = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId();
233
        
234
        File someFile = new File(workDir, "fileforothercommit");
235
        write(someFile, "fileforothercommit");
236
        add(someFile);
237
        commit(someFile);
238
239
        TestStatusListener listener = new TestStatusListener();
240
        client.addNotificationListener(listener);
241
        Map<File, GitStatus> statuses = client.getStatus(new File[] { workDir }, Constants.HEAD, NULL_PROGRESS_MONITOR);
242
        assertFalse(statuses.isEmpty());
243
        assertStatus(statuses, workDir, untracked, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false, listener);
244
        assertStatus(statuses, workDir, added_uptodate, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false, listener);
245
        assertStatus(statuses, workDir, added_modified, true, Status.STATUS_ADDED, Status.STATUS_MODIFIED, Status.STATUS_ADDED, false, listener);
246
        assertStatus(statuses, workDir, added_deleted, true, Status.STATUS_ADDED, Status.STATUS_REMOVED, Status.STATUS_NORMAL, false, listener);
247
        assertStatus(statuses, workDir, uptodate_uptodate, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false, listener);
248
        assertStatus(statuses, workDir, uptodate_modified, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false, listener);
249
        assertStatus(statuses, workDir, uptodate_deleted, true, Status.STATUS_NORMAL, Status.STATUS_REMOVED, Status.STATUS_REMOVED, false, listener);
250
        assertStatus(statuses, workDir, modified_uptodate, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false, listener);
251
        assertStatus(statuses, workDir, modified_modified, true, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false, listener);
252
        assertStatus(statuses, workDir, modified_reset, true, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, false, listener);
253
        assertStatus(statuses, workDir, modified_deleted, true, Status.STATUS_MODIFIED, Status.STATUS_REMOVED, Status.STATUS_REMOVED, false, listener);
254
        assertStatus(statuses, workDir, deleted_uptodate, true, Status.STATUS_REMOVED, Status.STATUS_NORMAL, Status.STATUS_REMOVED, false, listener);
255
        assertStatus(statuses, workDir, deleted_untracked, true, Status.STATUS_REMOVED, Status.STATUS_ADDED, Status.STATUS_NORMAL, false, listener);
256
        assertStatus(statuses, workDir, deleted_modified, true, Status.STATUS_REMOVED, Status.STATUS_ADDED, Status.STATUS_MODIFIED, false, listener);
257
        assertStatus(statuses, workDir, someFile, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false, listener);
258
        // what about isIgnored() here?
259
        assertStatus(statuses, workDir, ignored, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false, listener);
260
        
261
        listener = new TestStatusListener();
262
        client.addNotificationListener(listener);
263
        statuses = client.getStatus(new File[] { workDir }, revId, NULL_PROGRESS_MONITOR);
264
        assertFalse(statuses.isEmpty());
265
        assertStatus(statuses, workDir, untracked, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false, listener);
266
        assertStatus(statuses, workDir, added_uptodate, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false, listener);
267
        assertStatus(statuses, workDir, added_modified, true, Status.STATUS_ADDED, Status.STATUS_MODIFIED, Status.STATUS_ADDED, false, listener);
268
        assertStatus(statuses, workDir, added_deleted, true, Status.STATUS_ADDED, Status.STATUS_REMOVED, Status.STATUS_NORMAL, false, listener);
269
        assertStatus(statuses, workDir, uptodate_uptodate, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false, listener);
270
        assertStatus(statuses, workDir, uptodate_modified, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false, listener);
271
        assertStatus(statuses, workDir, uptodate_deleted, true, Status.STATUS_NORMAL, Status.STATUS_REMOVED, Status.STATUS_REMOVED, false, listener);
272
        assertStatus(statuses, workDir, modified_uptodate, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false, listener);
273
        assertStatus(statuses, workDir, modified_modified, true, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false, listener);
274
        assertStatus(statuses, workDir, modified_reset, true, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, false, listener);
275
        assertStatus(statuses, workDir, modified_deleted, true, Status.STATUS_MODIFIED, Status.STATUS_REMOVED, Status.STATUS_REMOVED, false, listener);
276
        assertStatus(statuses, workDir, deleted_uptodate, true, Status.STATUS_REMOVED, Status.STATUS_NORMAL, Status.STATUS_REMOVED, false, listener);
277
        assertStatus(statuses, workDir, deleted_untracked, true, Status.STATUS_REMOVED, Status.STATUS_ADDED, Status.STATUS_NORMAL, false, listener);
278
        assertStatus(statuses, workDir, deleted_modified, true, Status.STATUS_REMOVED, Status.STATUS_ADDED, Status.STATUS_MODIFIED, false, listener);
279
        // what about isIgnored() here?
280
        assertStatus(statuses, workDir, ignored, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false, listener);
281
        // file somefile was not known in that revision
282
        assertStatus(statuses, workDir, someFile, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false, listener);
283
    }
169
284
170
    public void testStatusSingleFile () throws Exception {
285
    public void testStatusSingleFile () throws Exception {
171
        File untracked = new File(workDir, "untracked");
286
        File untracked = new File(workDir, "untracked");

Return to bug 227348