Skip to content

Commit 810df28

Browse files
author
Kraig Amador
committed
Merge commit '8c1886ae4c94ce6ca1d9'
2 parents 5706ede + 8c1886a commit 810df28

7 files changed

Lines changed: 70 additions & 77 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>org.jenkinsci.plugins</groupId>
1010
<artifactId>git</artifactId>
11-
<version>1.1.10-SNAPSHOT</version>
11+
<version>1.1.11-SNAPSHOT</version>
1212
<packaging>hpi</packaging>
1313
<name>Jenkins GIT plugin</name>
1414
<description>Integrates Jenkins with GIT SCM</description>

src/main/java/hudson/plugins/git/GitAPI.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -979,16 +979,16 @@ public Repository getRepository() throws IOException {
979979
return new FileRepository(new File(workspace.getRemote(), Constants.DOT_GIT));
980980
}
981981

982-
public List<Tag> getTagsOnCommit(String revName) throws GitException, IOException {
983-
Repository db = getRepository();
984-
ObjectId commit = db.resolve(revName);
985-
List<Tag> ret = new ArrayList<Tag>();
982+
public List<Tag> getTagsOnCommit(final String revName) throws GitException,
983+
IOException {
984+
final Repository db = getRepository();
985+
final ObjectId commit = db.resolve(revName);
986+
final List<Tag> ret = new ArrayList<Tag>();
986987

987988
for (final Map.Entry<String, Ref> tag : db.getTags().entrySet()) {
988-
989-
Ref ref = db.getTags().get( tag.getKey() );
990-
if( ref.getObjectId().equals(commit) )
991-
ret.add( new Tag( tag.getKey(), ref.getObjectId() ) );
989+
final ObjectId tagId = tag.getValue().getObjectId();
990+
if (commit.equals(tagId))
991+
ret.add(new Tag(tag.getKey(), tagId));
992992
}
993993
return ret;
994994
}

src/main/java/hudson/plugins/git/GitSCM.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -425,27 +425,21 @@ public String getGitConfigEmail() {
425425
}
426426

427427
public String getGitConfigNameToUse() {
428-
String confName;
429-
String globalConfigName = ((DescriptorImpl) getDescriptor()).getGlobalConfigName();
430-
if ((fixEmptyAndTrim(globalConfigName) != null) && (gitConfigName == null)) {
431-
confName = globalConfigName;
432-
} else {
433-
confName = gitConfigName;
428+
String confName = fixEmptyAndTrim(gitConfigName);
429+
if (confName == null) {
430+
String globalConfigName = ((DescriptorImpl) getDescriptor()).getGlobalConfigName();
431+
confName = fixEmptyAndTrim(globalConfigName);
434432
}
435-
436-
return fixEmptyAndTrim(confName);
433+
return confName;
437434
}
438435

439436
public String getGitConfigEmailToUse() {
440-
String confEmail;
441-
String globalConfigEmail = ((DescriptorImpl) getDescriptor()).getGlobalConfigEmail();
442-
if ((fixEmptyAndTrim(globalConfigEmail) != null) && (gitConfigEmail == null)) {
443-
confEmail = globalConfigEmail;
444-
} else {
445-
confEmail = gitConfigEmail;
437+
String confEmail = fixEmptyAndTrim(gitConfigEmail);
438+
if (confEmail == null) {
439+
String globalConfigEmail = ((DescriptorImpl) getDescriptor()).getGlobalConfigEmail();
440+
confEmail = fixEmptyAndTrim(globalConfigEmail);
446441
}
447-
448-
return fixEmptyAndTrim(confEmail);
442+
return confEmail;
449443
}
450444

451445
public boolean getSkipTag() {
@@ -945,14 +939,6 @@ public Revision invoke(File localWorkspace, VirtualChannel channel)
945939
if (git.hasGitRepo()) {
946940
// It's an update
947941

948-
// Do we want to prune first?
949-
if (pruneBranches) {
950-
log.println("Pruning obsolete local branches");
951-
for (RemoteConfig remoteRepository : paramRepos) {
952-
git.prune(remoteRepository);
953-
}
954-
}
955-
956942
if (paramRepos.size() == 1)
957943
log.println("Fetching changes from 1 remote Git repository");
958944
else
@@ -972,6 +958,13 @@ public Revision invoke(File localWorkspace, VirtualChannel channel)
972958
listener.error("Could not fetch from any repository");
973959
throw new GitException("Could not fetch from any repository");
974960
}
961+
// Do we want to prune first?
962+
if (pruneBranches) {
963+
log.println("Pruning obsolete local branches");
964+
for (RemoteConfig remoteRepository : paramRepos) {
965+
git.prune(remoteRepository);
966+
}
967+
}
975968

976969
} else {
977970

src/main/java/hudson/plugins/git/SubmoduleCombinator.java

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Iterator;
1515
import java.util.List;
1616
import java.util.Map;
17+
import java.util.Map.Entry;
1718

1819
import org.eclipse.jgit.lib.ObjectId;
1920

@@ -59,18 +60,18 @@ public void createSubmoduleCombinations() throws GitException, IOException {
5960
}
6061

6162
// Remove any uninteresting branches
62-
63-
64-
65-
for (IndexEntry entry : moduleBranches.keySet()) {
66-
listener.getLogger().print("Submodule " + entry.getFile() + " branches");
67-
for (Revision br : moduleBranches.get(entry)) {
68-
listener.getLogger().print(" " + br.toString());
6963

70-
}
71-
listener.getLogger().print("\n");
64+
65+
66+
for (Entry<IndexEntry, Collection<Revision>> submodule : moduleBranches
67+
.entrySet()) {
68+
listener.getLogger().print(
69+
"Submodule " + submodule.getKey().getFile() + " branches");
70+
for (Revision br : submodule.getValue())
71+
listener.getLogger().print(" " + br.toString());
72+
listener.getLogger().print('\n');
7273
}
73-
74+
7475
// Make all the possible combinations
7576
List<Map<IndexEntry, Revision>> combinations = createCombinations(moduleBranches);
7677

@@ -110,12 +111,12 @@ public void createSubmoduleCombinations() throws GitException, IOException {
110111
int min = Integer.MAX_VALUE;
111112

112113
// But let's see if we can find the most appropriate place to create the branch
113-
for (ObjectId sha : entriesMap.keySet()) {
114-
List<IndexEntry> entries = entriesMap.get(sha);
115-
int value = difference(combination, entries);
114+
for (Entry<ObjectId, List<IndexEntry>> entry : entriesMap
115+
.entrySet()) {
116+
int value = difference(combination, entry.getValue());
116117
if (value > 0 && value < min) {
117118
min = value;
118-
sha1 = sha;
119+
sha1 = entry.getKey();
119120
}
120121

121122
if (min == 1) break; // look no further
@@ -151,36 +152,40 @@ protected void makeCombination(Map<IndexEntry, Revision> settings) {
151152
String name = "combine-" + tid + "-" + (idx++);
152153
git.branch(name);
153154
git.checkout(name);
154-
155-
String commit = "Jenkins generated combination of:\n";
156-
157-
for (IndexEntry submodule : settings.keySet()) {
158-
Revision branch = settings.get(submodule);
159-
commit += " " + submodule.getFile() + " " + branch.toString() + "\n";
155+
156+
StringBuilder commit = new StringBuilder(
157+
"Jenkins generated combination of:\n");
158+
159+
for (Entry<IndexEntry, Revision> setting : settings.entrySet()) {
160+
commit.append(' ').append(' ');
161+
commit.append(setting.getKey().getFile());
162+
commit.append(' ');
163+
commit.append(setting.getValue());
164+
commit.append('\n');
160165
}
161-
166+
162167
listener.getLogger().print(commit);
163-
164-
165-
for (IndexEntry submodule : settings.keySet()) {
166-
Revision branch = settings.get(submodule);
168+
169+
for (Entry<IndexEntry, Revision> setting : settings.entrySet()) {
170+
IndexEntry submodule = setting.getKey();
171+
Revision branch = setting.getValue();
167172
File subdir = new File(workspace, submodule.getFile());
168-
IGitAPI subGit = new GitAPI(git.getGitExe(), new FilePath(subdir), listener, git.getEnvironment());
169-
173+
IGitAPI subGit = new GitAPI(git.getGitExe(), new FilePath(subdir),
174+
listener, git.getEnvironment());
175+
170176
subGit.checkout(branch.sha1.name());
171177
git.add(submodule.file);
172-
173178
}
174179

175180
try {
176181
File f = File.createTempFile("gitcommit", ".txt");
177182
FileOutputStream fos = null;
178183
try {
179184
fos = new FileOutputStream(f);
180-
fos.write(commit.getBytes());
181-
}
182-
finally {
183-
fos.close();
185+
fos.write(commit.toString().getBytes());
186+
} finally {
187+
if (fos != null)
188+
fos.close();
184189
}
185190
git.commit(f);
186191
f.delete();

src/main/java/hudson/plugins/git/SubmoduleConfig.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package hudson.plugins.git;
22

3+
import com.google.common.base.Joiner;
4+
35
import java.util.regex.Pattern;
46

57
public class SubmoduleConfig implements java.io.Serializable {
@@ -40,13 +42,6 @@ public boolean branchMatchesInterest(Branch br) {
4042
}
4143

4244
public String getBranchesString() {
43-
String ret = "";
44-
45-
for (String branch : branches) {
46-
if (ret.length() > 0) ret += ",";
47-
ret += branch;
48-
}
49-
return ret;
50-
45+
return Joiner.on(',').join(branches);
5146
}
5247
}

src/main/java/hudson/plugins/git/opt/PreBuildMergeOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void setMergeTarget(String mergeTarget) {
4545

4646
@Exported
4747
public String getRemoteBranchName() {
48-
return mergeRemote.getName() + "/" + mergeTarget;
48+
return (mergeRemote == null) ? null : mergeRemote.getName() + "/" + mergeTarget;
4949
}
5050

5151
public boolean doMerge() {

src/main/resources/hudson/plugins/git/GitSCM/config.jelly

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,16 @@
123123
<table width="100%">
124124
<f:optionalBlock field="doMerge"
125125
title="${%Merge before build}"
126-
checked="${doMerge}">
126+
checked="${scm.mergeOptions.doMerge()}">
127127
<f:entry title="Name of repository: (default first specified, e.g. origin)" field="mergeRemote">
128-
<f:textbox id="git.mergeRemote" />
128+
<f:textbox id="git.mergeRemote" value="${scm.mergeOptions.getMergeRemote().getName()}"/>
129129
<!-- TODO add the check url. Note that we cannot rely on the repo.name tag to be at the root of the form -->
130130
<!-- checkUrl="'${rootURL}/scm/GitSCM/gitRemoteNameCheck?isMerge=true&amp;value='+escape(this.value)
131131
+encodeAllInputs('&amp;', this.form, 'repo.name')
132132
+encodeAllInputs('&amp;', this.form, 'repo.url')"/ -->
133133
</f:entry>
134134
<f:entry title="Branch to merge to: (e.g. master)" field="mergeTarget">
135-
<f:textbox id="git.mergeTarget" clazz="required"/>
135+
<f:textbox id="git.mergeTarget" value="${scm.mergeOptions.getMergeTarget()}" clazz="required"/>
136136
</f:entry>
137137
</f:optionalBlock>
138138
</table>

0 commit comments

Comments
 (0)