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

(-)libs.git/apichanges.xml (+18 lines)
Lines 112-117 Link Here
112
        <change>
112
        <change>
113
            <api name="gitlibrary_api"/>
113
            <api name="gitlibrary_api"/>
114
            <summary>The log command returns also branches containing the commits from the result.</summary>
114
            <summary>The log command returns also branches containing the commits from the result.</summary>
115
            <version major="1" minor="16"/>
116
            <date day="22" month="10" year="2013"/>
117
            <author login="ovrabec"/>
118
            <compatibility addition="yes"/>
119
            <description>
120
                <ul>
121
                <li>Adding new methods to GitClient allowing users to check a submodule's status, initialize them
122
                    after a clone and update them to a commit relevant to the state in the parent repository.</li>
123
                <li>Adding a new class GitSubmoduleStatus wrapping information about a submodule.</li>
124
                </ul>
125
            </description>
126
            <class package="org.netbeans.libs.git" name="GitClient"/>
127
            <class package="org.netbeans.libs.git" name="GitSubmoduleStatus"/>
128
            <issue number="237621"/>
129
        </change>
130
        <change>
131
            <api name="gitlibrary_api"/>
132
            <summary>The log command returns also branches containing the commits from the result.</summary>
115
            <version major="1" minor="14"/>
133
            <version major="1" minor="14"/>
116
            <date day="25" month="9" year="2013"/>
134
            <date day="25" month="9" year="2013"/>
117
            <author login="ovrabec"/>
135
            <author login="ovrabec"/>
(-)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.15
4
OpenIDE-Module-Specification-Version: 1.16
(-)libs.git/src/org/netbeans/libs/git/GitClassFactoryImpl.java (+6 lines)
Lines 54-59 Link Here
54
import org.eclipse.jgit.revwalk.RevCommit;
54
import org.eclipse.jgit.revwalk.RevCommit;
55
import org.eclipse.jgit.revwalk.RevObject;
55
import org.eclipse.jgit.revwalk.RevObject;
56
import org.eclipse.jgit.revwalk.RevTag;
56
import org.eclipse.jgit.revwalk.RevTag;
57
import org.eclipse.jgit.submodule.SubmoduleStatus;
57
import org.eclipse.jgit.transport.RemoteConfig;
58
import org.eclipse.jgit.transport.RemoteConfig;
58
import org.eclipse.jgit.transport.RemoteRefUpdate;
59
import org.eclipse.jgit.transport.RemoteRefUpdate;
59
import org.eclipse.jgit.transport.TrackingRefUpdate;
60
import org.eclipse.jgit.transport.TrackingRefUpdate;
Lines 185-188 Link Here
185
        branch.setTrackedBranch(trackedBranch);
186
        branch.setTrackedBranch(trackedBranch);
186
    }
187
    }
187
188
189
    @Override
190
    public GitSubmoduleStatus createSubmoduleStatus (SubmoduleStatus status, File folder) {
191
        return new GitSubmoduleStatus(status, folder);
192
    }
193
188
}
194
}
(-)libs.git/src/org/netbeans/libs/git/GitClient.java (+55 lines)
Lines 98-103 Link Here
98
import org.netbeans.libs.git.jgit.commands.StatusCommand;
98
import org.netbeans.libs.git.jgit.commands.StatusCommand;
99
import org.netbeans.libs.git.jgit.commands.UnignoreCommand;
99
import org.netbeans.libs.git.jgit.commands.UnignoreCommand;
100
import org.netbeans.libs.git.jgit.commands.SetUpstreamBranchCommand;
100
import org.netbeans.libs.git.jgit.commands.SetUpstreamBranchCommand;
101
import org.netbeans.libs.git.jgit.commands.SubmoduleInitializeCommand;
102
import org.netbeans.libs.git.jgit.commands.SubmoduleStatusCommand;
103
import org.netbeans.libs.git.jgit.commands.SubmoduleUpdateCommand;
101
import org.netbeans.libs.git.progress.FileListener;
104
import org.netbeans.libs.git.progress.FileListener;
102
import org.netbeans.libs.git.progress.NotificationListener;
105
import org.netbeans.libs.git.progress.NotificationListener;
103
import org.netbeans.libs.git.progress.ProgressMonitor;
106
import org.netbeans.libs.git.progress.ProgressMonitor;
Lines 655-660 Link Here
655
        cmd.execute();
658
        cmd.execute();
656
        return cmd.getFileDifferences();
659
        return cmd.getFileDifferences();
657
    }
660
    }
661
    
662
    /**
663
     * Scans for any submodules under given roots or in the whole repository and
664
     * returns their status.
665
     *
666
     * @param roots files to search for submodules. If empty all submodules will
667
     * be returned
668
     * @param monitor command progress monitor
669
     * @return status map of repository's submodules
670
     * @throws GitException an unexpected error occurs
671
     * @since 1.16
672
     */
673
    public Map<File, GitSubmoduleStatus> getSubmoduleStatus (File[] roots, ProgressMonitor monitor) throws GitException {
674
        Repository repository = gitRepository.getRepository();
675
        SubmoduleStatusCommand cmd = new SubmoduleStatusCommand(repository, getClassFactory(), roots, monitor);
676
        cmd.execute();
677
        return cmd.getStatuses();
678
    }
658
679
659
    /**
680
    /**
660
     * Returns remote configuration set up for this repository identified by a given remoteName
681
     * Returns remote configuration set up for this repository identified by a given remoteName
Lines 730-735 Link Here
730
    }
751
    }
731
752
732
    /**
753
    /**
754
     * Initializes submodules and registers them in .git/config file.
755
     *
756
     * @param roots modules to initialize
757
     * @param monitor progress monitor
758
     * @return initialized submodule statuses
759
     * @throws GitException an unexpected error occurs
760
     * @since 1.16
761
     */
762
    public Map<File, GitSubmoduleStatus> initializeSubmodules (File[] roots, ProgressMonitor monitor) throws GitException {
763
        Repository repository = gitRepository.getRepository();
764
        SubmoduleInitializeCommand cmd = new SubmoduleInitializeCommand(repository, getClassFactory(),
765
                roots, monitor);
766
        cmd.execute();
767
        return cmd.getStatuses();
768
    }
769
770
    /**
733
     * Returns files that are marked as modified between the HEAD and Index.
771
     * Returns files that are marked as modified between the HEAD and Index.
734
     * @param roots files or folders to search for modified files.
772
     * @param roots files or folders to search for modified files.
735
     * @param monitor progress monitor
773
     * @param monitor progress monitor
Lines 1065-1070 Link Here
1065
        return cmd.getModifiedIgnoreFiles();
1103
        return cmd.getModifiedIgnoreFiles();
1066
    }
1104
    }
1067
1105
1106
    /**
1107
     * Updates submodules. An equivalent to submodule update command.
1108
     *
1109
     * @param roots modules to update
1110
     * @param monitor progress monitor
1111
     * @return submodule statuses
1112
     * @throws GitException an unexpected error occurs
1113
     * @since 1.16
1114
     */
1115
    public Map<File, GitSubmoduleStatus> updateSubmodules (File[] roots, ProgressMonitor monitor) throws GitException {
1116
        Repository repository = gitRepository.getRepository();
1117
        SubmoduleUpdateCommand cmd = new SubmoduleUpdateCommand(repository, getClassFactory(),
1118
                roots, monitor);
1119
        cmd.execute();
1120
        return cmd.getStatuses();
1121
    }
1122
1068
    private GitClassFactory getClassFactory () {
1123
    private GitClassFactory getClassFactory () {
1069
        if (gitFactory == null) {
1124
        if (gitFactory == null) {
1070
            gitFactory = GitClassFactoryImpl.getInstance();
1125
            gitFactory = GitClassFactoryImpl.getInstance();
(-)libs.git/src/org/netbeans/libs/git/GitSubmoduleStatus.java (+125 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 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 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.libs.git;
43
44
import java.io.File;
45
import org.eclipse.jgit.submodule.SubmoduleStatus;
46
import org.eclipse.jgit.submodule.SubmoduleStatusType;
47
48
/**
49
 * Describes current status of a repository's submodule
50
 *
51
 * @author Ondrej Vrabec
52
 * @since 1.16
53
 */
54
public final class GitSubmoduleStatus {
55
56
    private final SubmoduleStatus delegate;
57
    private final StatusType statusType;
58
    private final File folder;
59
60
    /**
61
     * Submodule's status
62
     */
63
    public enum StatusType {
64
65
        /**
66
         * Submodule's configuration is missing
67
         */
68
        MISSING,
69
        /**
70
         * Submodule's Git repository is not initialized
71
         */
72
        UNINITIALIZED,
73
        /**
74
         * Submodule's Git repository is initialized
75
         */
76
        INITIALIZED,
77
        /**
78
         * Submodule checked out commit is different than the commit referenced
79
         * in the index tree
80
         */
81
        REV_CHECKED_OUT;
82
    }
83
84
    GitSubmoduleStatus (SubmoduleStatus delegate, File folder) {
85
        this.delegate = delegate;
86
        this.folder = folder;
87
        this.statusType = parseStatus(delegate.getType());
88
    }
89
90
    /**
91
     * Returns status of the submodule
92
     * @return submodule's status
93
     */
94
    public StatusType getStatus () {
95
        return statusType;
96
    }
97
98
    /**
99
     * Returns the submodule's root folder.
100
     * @return submodule's root folder.
101
     */
102
    public File getSubmoduleFolder () {
103
        return folder;
104
    }
105
106
    /**
107
     * Returns the commit id of the currently checked-out commit.
108
     * @return submodule's commit id.
109
     */
110
    public String getHeadId () {
111
        return delegate.getHeadId().getName();
112
    }
113
114
    /**
115
     * Returns the state of the index in the submodule.
116
     * @return submodule's index tree id.
117
     */
118
    public String getIndexId () {
119
        return delegate.getIndexId().getName();
120
    }
121
122
    static StatusType parseStatus (SubmoduleStatusType status) {
123
        return StatusType.valueOf(status.name());
124
    }
125
}
(-)libs.git/src/org/netbeans/libs/git/jgit/GitClassFactory.java (+4 lines)
Lines 55-60 Link Here
55
import org.eclipse.jgit.revwalk.RevCommit;
55
import org.eclipse.jgit.revwalk.RevCommit;
56
import org.eclipse.jgit.revwalk.RevObject;
56
import org.eclipse.jgit.revwalk.RevObject;
57
import org.eclipse.jgit.revwalk.RevTag;
57
import org.eclipse.jgit.revwalk.RevTag;
58
import org.eclipse.jgit.submodule.SubmoduleStatus;
58
import org.eclipse.jgit.transport.RemoteConfig;
59
import org.eclipse.jgit.transport.RemoteConfig;
59
import org.eclipse.jgit.transport.RemoteRefUpdate;
60
import org.eclipse.jgit.transport.RemoteRefUpdate;
60
import org.eclipse.jgit.transport.TrackingRefUpdate;
61
import org.eclipse.jgit.transport.TrackingRefUpdate;
Lines 73-78 Link Here
73
import org.netbeans.libs.git.GitRevisionInfo.GitFileInfo;
74
import org.netbeans.libs.git.GitRevisionInfo.GitFileInfo;
74
import org.netbeans.libs.git.GitStatus;
75
import org.netbeans.libs.git.GitStatus;
75
import org.netbeans.libs.git.GitStatus.Status;
76
import org.netbeans.libs.git.GitStatus.Status;
77
import org.netbeans.libs.git.GitSubmoduleStatus;
76
import org.netbeans.libs.git.GitTag;
78
import org.netbeans.libs.git.GitTag;
77
import org.netbeans.libs.git.GitTransportUpdate;
79
import org.netbeans.libs.git.GitTransportUpdate;
78
import org.netbeans.libs.git.GitUser;
80
import org.netbeans.libs.git.GitUser;
Lines 113-118 Link Here
113
    public abstract GitStatus createStatus (boolean tracked, String path, String workTreePath, File file, 
115
    public abstract GitStatus createStatus (boolean tracked, String path, String workTreePath, File file, 
114
                Status statusHeadIndex, Status statusIndexWC, Status statusHeadWC, 
116
                Status statusHeadIndex, Status statusIndexWC, Status statusHeadWC, 
115
                GitConflictDescriptor conflictDescriptor, boolean folder, DiffEntry diffEntry);
117
                GitConflictDescriptor conflictDescriptor, boolean folder, DiffEntry diffEntry);
118
    
119
    public abstract GitSubmoduleStatus createSubmoduleStatus (SubmoduleStatus status, File folder);
116
120
117
    public abstract GitTag createTag (RevTag revTag);
121
    public abstract GitTag createTag (RevTag revTag);
118
122
(-)libs.git/src/org/netbeans/libs/git/jgit/commands/SubmoduleInitializeCommand.java (+104 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 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 2013 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.libs.git.jgit.commands;
44
45
import java.io.File;
46
import java.util.Map;
47
import org.eclipse.jgit.api.Git;
48
import org.eclipse.jgit.api.errors.GitAPIException;
49
import org.eclipse.jgit.api.errors.JGitInternalException;
50
import org.eclipse.jgit.lib.Repository;
51
import org.netbeans.libs.git.GitException;
52
import org.netbeans.libs.git.GitSubmoduleStatus;
53
import org.netbeans.libs.git.jgit.DelegatingGitProgressMonitor;
54
import org.netbeans.libs.git.jgit.GitClassFactory;
55
import org.netbeans.libs.git.jgit.Utils;
56
import org.netbeans.libs.git.progress.ProgressMonitor;
57
58
/**
59
 *
60
 * @author Ondrej Vrabec
61
 */
62
public class SubmoduleInitializeCommand extends GitCommand {
63
    
64
    private final File[] roots;
65
    private final SubmoduleStatusCommand statusCmd;
66
67
    public SubmoduleInitializeCommand (Repository repository, GitClassFactory classFactory,
68
            File[] roots, ProgressMonitor monitor) {
69
        super(repository, classFactory, monitor);
70
        this.roots = roots;
71
        this.statusCmd = new SubmoduleStatusCommand(repository,
72
                    getClassFactory(), roots, new DelegatingGitProgressMonitor(monitor));
73
    }
74
75
    @Override
76
    protected void run () throws GitException {
77
        Repository repository = getRepository();
78
        File workTree = repository.getWorkTree();
79
        org.eclipse.jgit.api.SubmoduleInitCommand cmd = new Git(repository).submoduleInit();
80
        for (String path : Utils.getRelativePaths(workTree, roots)) {
81
            cmd.addPath(path);
82
        }
83
        try {
84
            cmd.call();
85
            statusCmd.run();
86
        } catch (GitAPIException | JGitInternalException ex) {
87
            throw new GitException(ex);
88
        }
89
    }
90
91
    @Override
92
    protected String getCommandDescription () {
93
        StringBuilder sb = new StringBuilder("git submodule initialize"); //NOI18N
94
        for (File root : roots) {
95
            sb.append(" ").append(root.getAbsolutePath());
96
        }
97
        return sb.toString();
98
    }
99
100
    public Map<File, GitSubmoduleStatus> getStatuses () {
101
        return statusCmd.getStatuses();
102
    }
103
    
104
}
(-)libs.git/src/org/netbeans/libs/git/jgit/commands/SubmoduleStatusCommand.java (+108 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 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 2013 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.libs.git.jgit.commands;
44
45
import java.io.File;
46
import java.util.LinkedHashMap;
47
import java.util.Map;
48
import org.eclipse.jgit.api.Git;
49
import org.eclipse.jgit.api.errors.GitAPIException;
50
import org.eclipse.jgit.api.errors.JGitInternalException;
51
import org.eclipse.jgit.lib.Repository;
52
import org.eclipse.jgit.submodule.SubmoduleStatus;
53
import org.netbeans.libs.git.GitException;
54
import org.netbeans.libs.git.GitSubmoduleStatus;
55
import org.netbeans.libs.git.jgit.GitClassFactory;
56
import org.netbeans.libs.git.jgit.Utils;
57
import org.netbeans.libs.git.progress.ProgressMonitor;
58
59
/**
60
 *
61
 * @author Ondrej Vrabec
62
 */
63
public class SubmoduleStatusCommand extends GitCommand {
64
    
65
    private final File[] roots;
66
    private final LinkedHashMap<File, GitSubmoduleStatus> statuses;
67
68
    public SubmoduleStatusCommand (Repository repository, GitClassFactory classFactory,
69
            File[] roots, ProgressMonitor monitor) {
70
        super(repository, classFactory, monitor);
71
        this.roots = roots;
72
        statuses = new LinkedHashMap<>();
73
    }
74
75
    @Override
76
    protected void run () throws GitException {
77
        Repository repository = getRepository();
78
        File workTree = repository.getWorkTree();
79
        org.eclipse.jgit.api.SubmoduleStatusCommand cmd = new Git(repository).submoduleStatus();
80
        for (String path : Utils.getRelativePaths(workTree, roots)) {
81
            cmd.addPath(path);
82
        }
83
        try {
84
            Map<String, SubmoduleStatus> result = cmd.call();
85
            GitClassFactory fac = getClassFactory();
86
            for (Map.Entry<String, SubmoduleStatus> e : result.entrySet()) {
87
                File root = new File(workTree, e.getKey());
88
                statuses.put(root, fac.createSubmoduleStatus(e.getValue(), root));
89
            }
90
        } catch (GitAPIException | JGitInternalException ex) {
91
            throw new GitException(ex);
92
        }
93
    }
94
95
    @Override
96
    protected String getCommandDescription () {
97
        StringBuilder sb = new StringBuilder("git submodule status"); //NOI18N
98
        for (File root : roots) {
99
            sb.append(" ").append(root.getAbsolutePath());
100
        }
101
        return sb.toString();
102
    }
103
104
    public Map<File, GitSubmoduleStatus> getStatuses () {
105
        return statuses;
106
    }
107
    
108
}
(-)libs.git/src/org/netbeans/libs/git/jgit/commands/SubmoduleUpdateCommand.java (+108 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 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 2013 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.libs.git.jgit.commands;
44
45
import java.io.File;
46
import java.util.Map;
47
import org.eclipse.jgit.api.Git;
48
import org.eclipse.jgit.api.errors.GitAPIException;
49
import org.eclipse.jgit.api.errors.JGitInternalException;
50
import org.eclipse.jgit.lib.Repository;
51
import org.netbeans.libs.git.GitException;
52
import org.netbeans.libs.git.GitSubmoduleStatus;
53
import org.netbeans.libs.git.jgit.DelegatingGitProgressMonitor;
54
import org.netbeans.libs.git.jgit.DelegatingProgressMonitor;
55
import org.netbeans.libs.git.jgit.GitClassFactory;
56
import org.netbeans.libs.git.jgit.Utils;
57
import org.netbeans.libs.git.progress.ProgressMonitor;
58
59
/**
60
 *
61
 * @author Ondrej Vrabec
62
 */
63
public class SubmoduleUpdateCommand extends GitCommand {
64
    
65
    private final File[] roots;
66
    private final SubmoduleStatusCommand statusCmd;
67
    private final ProgressMonitor monitor;
68
69
    public SubmoduleUpdateCommand (Repository repository, GitClassFactory classFactory,
70
            File[] roots, ProgressMonitor monitor) {
71
        super(repository, classFactory, monitor);
72
        this.monitor = monitor;
73
        this.roots = roots;
74
        this.statusCmd = new SubmoduleStatusCommand(repository,
75
                    getClassFactory(), roots, new DelegatingGitProgressMonitor(monitor));
76
    }
77
78
    @Override
79
    protected void run () throws GitException {
80
        Repository repository = getRepository();
81
        File workTree = repository.getWorkTree();
82
        org.eclipse.jgit.api.SubmoduleUpdateCommand cmd = new Git(repository).submoduleUpdate();
83
        for (String path : Utils.getRelativePaths(workTree, roots)) {
84
            cmd.addPath(path);
85
        }
86
        try {
87
            cmd.setProgressMonitor(new DelegatingProgressMonitor(monitor));
88
            cmd.call();
89
            statusCmd.run();
90
        } catch (GitAPIException | JGitInternalException ex) {
91
            throw new GitException(ex);
92
        }
93
    }
94
95
    @Override
96
    protected String getCommandDescription () {
97
        StringBuilder sb = new StringBuilder("git submodule initialize"); //NOI18N
98
        for (File root : roots) {
99
            sb.append(" ").append(root.getAbsolutePath());
100
        }
101
        return sb.toString();
102
    }
103
104
    public Map<File, GitSubmoduleStatus> getStatuses () {
105
        return statusCmd.getStatuses();
106
    }
107
    
108
}
(-)libs.git/test/unit/src/org/netbeans/libs/git/GitEnumsStateTest.java (+7 lines)
Lines 47-52 Link Here
47
import org.eclipse.jgit.api.RebaseResult;
47
import org.eclipse.jgit.api.RebaseResult;
48
import org.eclipse.jgit.lib.RefUpdate;
48
import org.eclipse.jgit.lib.RefUpdate;
49
import org.eclipse.jgit.lib.RepositoryState;
49
import org.eclipse.jgit.lib.RepositoryState;
50
import org.eclipse.jgit.submodule.SubmoduleStatusType;
50
import org.eclipse.jgit.transport.RemoteRefUpdate;
51
import org.eclipse.jgit.transport.RemoteRefUpdate;
51
import org.netbeans.libs.git.jgit.AbstractGitTestCase;
52
import org.netbeans.libs.git.jgit.AbstractGitTestCase;
52
53
Lines 89-92 Link Here
89
            assertNotNull(GitRebaseResult.parseRebaseStatus(status));
90
            assertNotNull(GitRebaseResult.parseRebaseStatus(status));
90
        }
91
        }
91
    }
92
    }
93
    
94
    public void testSubmoduleStatus () {
95
        for (SubmoduleStatusType status : SubmoduleStatusType.values()) {
96
            assertNotNull(GitSubmoduleStatus.parseStatus(status));
97
        }
98
    }
92
}
99
}
(-)libs.git/test/unit/src/org/netbeans/libs/git/jgit/CommandsTestSuite.java (+2 lines)
Lines 76-81 Link Here
76
import org.netbeans.libs.git.jgit.commands.RevertTest;
76
import org.netbeans.libs.git.jgit.commands.RevertTest;
77
import org.netbeans.libs.git.jgit.commands.SetUpstreamBranchTest;
77
import org.netbeans.libs.git.jgit.commands.SetUpstreamBranchTest;
78
import org.netbeans.libs.git.jgit.commands.StatusTest;
78
import org.netbeans.libs.git.jgit.commands.StatusTest;
79
import org.netbeans.libs.git.jgit.commands.SubmoduleTest;
79
import org.netbeans.libs.git.jgit.commands.TagTest;
80
import org.netbeans.libs.git.jgit.commands.TagTest;
80
import org.netbeans.libs.git.jgit.commands.UnignoreTest;
81
import org.netbeans.libs.git.jgit.commands.UnignoreTest;
81
82
Lines 122-127 Link Here
122
        suite.addTestSuite(ResetTest.class);
123
        suite.addTestSuite(ResetTest.class);
123
        suite.addTestSuite(SetUpstreamBranchTest.class);
124
        suite.addTestSuite(SetUpstreamBranchTest.class);
124
        suite.addTestSuite(StatusTest.class);
125
        suite.addTestSuite(StatusTest.class);
126
        suite.addTestSuite(SubmoduleTest.class);
125
        suite.addTestSuite(TagTest.class);
127
        suite.addTestSuite(TagTest.class);
126
        suite.addTestSuite(UnignoreTest.class);
128
        suite.addTestSuite(UnignoreTest.class);
127
        return suite;
129
        return suite;
(-)libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/SubmoduleTest.java (+230 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 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 2013 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.Arrays;
48
import java.util.Map;
49
import org.eclipse.jgit.lib.Repository;
50
import org.eclipse.jgit.transport.RemoteConfig;
51
import org.eclipse.jgit.transport.URIish;
52
import org.netbeans.libs.git.GitClient;
53
import org.netbeans.libs.git.GitSubmoduleStatus;
54
import org.netbeans.libs.git.jgit.AbstractGitTestCase;
55
import org.netbeans.libs.git.jgit.Utils;
56
57
/**
58
 *
59
 * @author Ondrej Vrabec
60
 */
61
public class SubmoduleTest extends AbstractGitTestCase {
62
    
63
    private Repository repository;
64
    private Repository repositorySM1;
65
    private Repository repositorySM2;
66
    private File workDir;
67
    private File moduleRepo;
68
    private File submoduleRepo1;
69
    private File submoduleRepo2;
70
    private File submoduleFolder1;
71
    private File submoduleFolder2;
72
    private File f1;
73
    private File f2;
74
    private File f;
75
76
    public SubmoduleTest (String testName) throws IOException {
77
        super(testName);
78
    }
79
80
    @Override
81
    protected void setUp() throws Exception {
82
        super.setUp();
83
        workDir = getWorkingDirectory();
84
        repository = getRepository(getLocalGitRepository());
85
        
86
        moduleRepo = new File(workDir.getParentFile(), "module");
87
        GitClient client = getClient(moduleRepo);
88
        client.init(NULL_PROGRESS_MONITOR);
89
        submoduleRepo1 = new File(workDir.getParentFile(), "submodule1");
90
        client = getClient(submoduleRepo1);
91
        client.init(NULL_PROGRESS_MONITOR);
92
        submoduleRepo2 = new File(workDir.getParentFile(), "submodule2");
93
        client = getClient(submoduleRepo2);
94
        client.init(NULL_PROGRESS_MONITOR);
95
        
96
        client = getClient(workDir);
97
        f = new File(workDir, "f");
98
        write(f, "init");
99
        client.add(new File[] { f }, NULL_PROGRESS_MONITOR);
100
        client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
101
        RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
102
        cfg.addURI(new URIish(moduleRepo.toURI().toURL().toString()));
103
        cfg.update(repository.getConfig());
104
        repository.getConfig().save();
105
        client.push("origin", Arrays.asList("refs/heads/master:refs/heads/master"),
106
                Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
107
        
108
        File submodules = new File(workDir, "submodules");
109
        
110
        submoduleFolder1 = new File(submodules, "submodule1");
111
        submoduleFolder1.mkdirs();
112
        getClient(submoduleFolder1).init(NULL_PROGRESS_MONITOR);
113
        f1 = new File(submoduleFolder1, "file");
114
        write(f1, "init");
115
        getClient(submoduleFolder1).add(new File[] { f1 }, NULL_PROGRESS_MONITOR);
116
        getClient(submoduleFolder1).commit(new File[] { f1 }, "init SM1 commit", null, null, NULL_PROGRESS_MONITOR);
117
        repositorySM1 = getRepository(getClient(submoduleFolder1));
118
        cfg = new RemoteConfig(repositorySM1.getConfig(), "origin");
119
        cfg.addURI(new URIish(submoduleRepo1.toURI().toURL().toString()));
120
        cfg.update(repositorySM1.getConfig());
121
        repositorySM1.getConfig().save();
122
        getClient(submoduleFolder1).push("origin", Arrays.asList("refs/heads/master:refs/heads/master"),
123
                Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
124
        
125
        
126
        submoduleFolder2 = new File(submodules, "submodule2");
127
        submoduleFolder2.mkdirs();
128
        getClient(submoduleFolder2).init(NULL_PROGRESS_MONITOR);
129
        f2 = new File(submoduleFolder2, "file");
130
        write(f2, "init");
131
        getClient(submoduleFolder2).add(new File[] { f2 }, NULL_PROGRESS_MONITOR);
132
        getClient(submoduleFolder2).commit(new File[] { f2 }, "init SM1 commit", null, null, NULL_PROGRESS_MONITOR);
133
        repositorySM2 = getRepository(getClient(submoduleFolder2));
134
        cfg = new RemoteConfig(repositorySM2.getConfig(), "origin");
135
        cfg.addURI(new URIish(submoduleRepo2.toURI().toURL().toString()));
136
        cfg.update(repositorySM2.getConfig());
137
        repositorySM2.getConfig().save();
138
        getClient(submoduleFolder2).push("origin", Arrays.asList("refs/heads/master:refs/heads/master"),
139
                Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
140
    }
141
    
142
    public void testStatusEmpty () throws Exception {
143
        GitClient client = getClient(workDir);
144
        assertEquals(0, client.getSubmoduleStatus(new File[0], NULL_PROGRESS_MONITOR).size());
145
    }
146
    
147
    public void testStatusUninitialized () throws Exception {
148
        prepareUninitializedWorkdir();
149
        
150
        GitClient client = getClient(workDir);
151
        Map<File, GitSubmoduleStatus> status = client.getSubmoduleStatus(new File[] { f } , NULL_PROGRESS_MONITOR);
152
        assertEquals(0, status.size());
153
        
154
        status = client.getSubmoduleStatus(new File[] { submoduleFolder1 } , NULL_PROGRESS_MONITOR);
155
        assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.UNINITIALIZED,
156
                submoduleFolder1);
157
        
158
        status = client.getSubmoduleStatus(new File[] { submoduleFolder2 } , NULL_PROGRESS_MONITOR);
159
        assertStatus(status.get(submoduleFolder2), GitSubmoduleStatus.StatusType.UNINITIALIZED,
160
                submoduleFolder2);
161
        
162
        status = client.getSubmoduleStatus(new File[0], NULL_PROGRESS_MONITOR);
163
        assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.UNINITIALIZED,
164
                submoduleFolder1);
165
        assertStatus(status.get(submoduleFolder2), GitSubmoduleStatus.StatusType.UNINITIALIZED,
166
                submoduleFolder2);
167
    }
168
    
169
    public void testInitialize () throws Exception {
170
        prepareUninitializedWorkdir();
171
        
172
        GitClient client = getClient(workDir);
173
        Map<File, GitSubmoduleStatus> status = client.getSubmoduleStatus(new File[] { f } , NULL_PROGRESS_MONITOR);
174
        assertEquals(0, status.size());
175
        
176
        status = client.getSubmoduleStatus(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR);
177
        assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.UNINITIALIZED,
178
                submoduleFolder1);
179
        
180
        status = client.initializeSubmodules(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR);
181
        assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.UNINITIALIZED,
182
                submoduleFolder1);
183
    }
184
    
185
    public void testUpdate () throws Exception {
186
        prepareUninitializedWorkdir();
187
        
188
        GitClient client = getClient(workDir);
189
        Map<File, GitSubmoduleStatus> status = client.getSubmoduleStatus(new File[] { f } , NULL_PROGRESS_MONITOR);
190
        assertEquals(0, status.size());
191
        
192
        status = client.initializeSubmodules(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR);
193
        assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.UNINITIALIZED,
194
                submoduleFolder1);
195
        status = client.updateSubmodules(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR);
196
        assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.INITIALIZED,
197
                submoduleFolder1);
198
    }
199
200
    private void prepareUninitializedWorkdir () throws Exception {
201
        File gmFile = new File(workDir, ".gitmodules");
202
        gmFile.createNewFile();
203
        write(gmFile, "[submodule \"submodules/submodule1\"]\n" +
204
"        path = submodules/submodule1\n" +
205
"        url = " + submoduleRepo1.toURI().toURL().toString() + "\n" +
206
"[submodule \"submodules/submodule2\"]\n" +
207
"        path = submodules/submodule2\n" +
208
"        url = " + submoduleRepo2.toURI().toURL().toString() + "\n");
209
        
210
        GitClient client = getClient(workDir);
211
        client.add(new File[] { gmFile, submoduleFolder1, submoduleFolder2 }, NULL_PROGRESS_MONITOR);
212
        client.commit(new File[0], "adding modules", null, null, NULL_PROGRESS_MONITOR);
213
        client.push("origin", Arrays.asList("refs/heads/master:refs/heads/master"),
214
                Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
215
        
216
        Utils.deleteRecursively(submoduleFolder1);
217
        Utils.deleteRecursively(submoduleFolder2);
218
        assertFalse(submoduleFolder1.exists());
219
        assertFalse(submoduleFolder2.exists());
220
        client.reset("master", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR);
221
        assertTrue(submoduleFolder1.exists());
222
        assertTrue(submoduleFolder2.exists());
223
    }
224
225
    private void assertStatus (GitSubmoduleStatus status, GitSubmoduleStatus.StatusType statusKind,
226
            File submoduleRoot) {
227
        assertEquals(statusKind, status.getStatus());
228
        assertEquals(submoduleRoot, status.getSubmoduleFolder());
229
    }
230
}

Return to bug 237621