aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2015-10-01 16:07:02 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2015-10-01 16:55:26 +0900
commit3096ab6502471ec2f2f76040f72d31680e2b61ca (patch)
tree768a981be6fe27a9d11fa93dec6f136943535b49 /org.eclipse.jgit.pgm
parent581698331a0e80eb02fdd7549cfce1c0e6f9ac87 (diff)
downloadjgit-3096ab6502471ec2f2f76040f72d31680e2b61ca.tar.gz
jgit-3096ab6502471ec2f2f76040f72d31680e2b61ca.zip
pgm: Create instances of Git in try-with-resource
To prevent potential resource leak. Change-Id: I8ac4ae61193324849bafb46501a55f93c5029a4e Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java12
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java4
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java40
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java78
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java62
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java29
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java51
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java29
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java37
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java16
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java28
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java11
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java14
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java39
14 files changed, 235 insertions, 215 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java
index 12aac77e9d..c36c485197 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java
@@ -62,10 +62,12 @@ class Add extends TextBuiltin {
@Override
protected void run() throws Exception {
- AddCommand addCmd = new Git(db).add();
- addCmd.setUpdate(update);
- for (String p : filepatterns)
- addCmd.addFilepattern(p);
- addCmd.call();
+ try (Git git = new Git(db)) {
+ AddCommand addCmd = git.add();
+ addCmd.setUpdate(update);
+ for (String p : filepatterns)
+ addCmd.addFilepattern(p);
+ addCmd.call();
+ }
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
index 80bb9ec9df..fe2ba83bc6 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
@@ -87,8 +87,8 @@ class Archive extends TextBuiltin {
else
stream = outs;
- try {
- ArchiveCommand cmd = new Git(db).archive()
+ try (Git git = new Git(db)) {
+ ArchiveCommand cmd = git.archive()
.setTree(tree)
.setFormat(format)
.setPrefix(prefix)
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java
index 72e37158cd..83a1ca7e25 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java
@@ -186,29 +186,31 @@ class Branch extends TextBuiltin {
// This can happen if HEAD is stillborn
if (head != null) {
String current = head.getLeaf().getName();
- ListBranchCommand command = new Git(db).branchList();
- if (all)
- command.setListMode(ListMode.ALL);
- else if (remote)
- command.setListMode(ListMode.REMOTE);
+ try (Git git = new Git(db)) {
+ ListBranchCommand command = git.branchList();
+ if (all)
+ command.setListMode(ListMode.ALL);
+ else if (remote)
+ command.setListMode(ListMode.REMOTE);
- if (containsCommitish != null)
- command.setContains(containsCommitish);
+ if (containsCommitish != null)
+ command.setContains(containsCommitish);
- List<Ref> refs = command.call();
- for (Ref ref : refs) {
- if (ref.getName().equals(Constants.HEAD))
- addRef("(no branch)", head); //$NON-NLS-1$
- }
+ List<Ref> refs = command.call();
+ for (Ref ref : refs) {
+ if (ref.getName().equals(Constants.HEAD))
+ addRef("(no branch)", head); //$NON-NLS-1$
+ }
- addRefs(refs, Constants.R_HEADS);
- addRefs(refs, Constants.R_REMOTES);
+ addRefs(refs, Constants.R_HEADS);
+ addRefs(refs, Constants.R_REMOTES);
- try (ObjectReader reader = db.newObjectReader()) {
- for (final Entry<String, Ref> e : printRefs.entrySet()) {
- final Ref ref = e.getValue();
- printHead(reader, e.getKey(),
- current.equals(ref.getName()), ref);
+ try (ObjectReader reader = db.newObjectReader()) {
+ for (final Entry<String, Ref> e : printRefs.entrySet()) {
+ final Ref ref = e.getValue();
+ printHead(reader, e.getKey(),
+ current.equals(ref.getName()), ref);
+ }
}
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java
index 56d4fcff02..45794629ec 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java
@@ -89,47 +89,49 @@ class Checkout extends TextBuiltin {
throw die(CLIText.get().onBranchToBeBorn);
}
- CheckoutCommand command = new Git(db).checkout();
- if (paths.size() > 0) {
- command.setStartPoint(name);
- for (String path : paths)
- command.addPath(path);
- } else {
- command.setCreateBranch(createBranch);
- command.setName(name);
- command.setForce(force);
- command.setOrphan(orphan);
- }
- try {
- String oldBranch = db.getBranch();
- Ref ref = command.call();
- if (ref == null)
- return;
- if (Repository.shortenRefName(ref.getName()).equals(oldBranch)) {
+ try (Git git = new Git(db)) {
+ CheckoutCommand command = git.checkout();
+ if (paths.size() > 0) {
+ command.setStartPoint(name);
+ for (String path : paths)
+ command.addPath(path);
+ } else {
+ command.setCreateBranch(createBranch);
+ command.setName(name);
+ command.setForce(force);
+ command.setOrphan(orphan);
+ }
+ try {
+ String oldBranch = db.getBranch();
+ Ref ref = command.call();
+ if (ref == null)
+ return;
+ if (Repository.shortenRefName(ref.getName()).equals(oldBranch)) {
+ outw.println(MessageFormat.format(
+ CLIText.get().alreadyOnBranch,
+ name));
+ return;
+ }
+ if (createBranch || orphan)
+ outw.println(MessageFormat.format(
+ CLIText.get().switchedToNewBranch, name));
+ else
+ outw.println(MessageFormat.format(
+ CLIText.get().switchedToBranch,
+ Repository.shortenRefName(ref.getName())));
+ } catch (RefNotFoundException e) {
outw.println(MessageFormat.format(
- CLIText.get().alreadyOnBranch,
+ CLIText.get().pathspecDidNotMatch,
+ name));
+ } catch (RefAlreadyExistsException e) {
+ throw die(MessageFormat.format(CLIText.get().branchAlreadyExists,
name));
- return;
+ } catch (CheckoutConflictException e) {
+ outw.println(CLIText.get().checkoutConflict);
+ for (String path : e.getConflictingPaths())
+ outw.println(MessageFormat.format(
+ CLIText.get().checkoutConflictPathLine, path));
}
- if (createBranch || orphan)
- outw.println(MessageFormat.format(
- CLIText.get().switchedToNewBranch, name));
- else
- outw.println(MessageFormat.format(
- CLIText.get().switchedToBranch,
- Repository.shortenRefName(ref.getName())));
- } catch (RefNotFoundException e) {
- outw.println(MessageFormat.format(
- CLIText.get().pathspecDidNotMatch,
- name));
- } catch (RefAlreadyExistsException e) {
- throw die(MessageFormat.format(CLIText.get().branchAlreadyExists,
- name));
- } catch (CheckoutConflictException e) {
- outw.println(CLIText.get().checkoutConflict);
- for (String path : e.getConflictingPaths())
- outw.println(MessageFormat.format(
- CLIText.get().checkoutConflictPathLine, path));
}
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
index 14c449a6b3..f18242d684 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
@@ -80,37 +80,39 @@ class Commit extends TextBuiltin {
@Override
protected void run() throws NoHeadException, NoMessageException,
ConcurrentRefUpdateException, JGitInternalException, Exception {
- CommitCommand commitCmd = new Git(db).commit();
- if (author != null)
- commitCmd.setAuthor(RawParseUtils.parsePersonIdent(author));
- if (message != null)
- commitCmd.setMessage(message);
- if (only && paths.isEmpty())
- throw die(CLIText.get().pathsRequired);
- if (only && all)
- throw die(CLIText.get().onlyOneOfIncludeOnlyAllInteractiveCanBeUsed);
- if (!paths.isEmpty())
- for (String p : paths)
- commitCmd.setOnly(p);
- commitCmd.setAmend(amend);
- commitCmd.setAll(all);
- Ref head = db.getRef(Constants.HEAD);
- RevCommit commit;
- try {
- commit = commitCmd.call();
- } catch (JGitInternalException e) {
- throw die(e.getMessage());
- }
+ try (Git git = new Git(db)) {
+ CommitCommand commitCmd = git.commit();
+ if (author != null)
+ commitCmd.setAuthor(RawParseUtils.parsePersonIdent(author));
+ if (message != null)
+ commitCmd.setMessage(message);
+ if (only && paths.isEmpty())
+ throw die(CLIText.get().pathsRequired);
+ if (only && all)
+ throw die(CLIText.get().onlyOneOfIncludeOnlyAllInteractiveCanBeUsed);
+ if (!paths.isEmpty())
+ for (String p : paths)
+ commitCmd.setOnly(p);
+ commitCmd.setAmend(amend);
+ commitCmd.setAll(all);
+ Ref head = db.getRef(Constants.HEAD);
+ RevCommit commit;
+ try {
+ commit = commitCmd.call();
+ } catch (JGitInternalException e) {
+ throw die(e.getMessage());
+ }
- String branchName;
- if (!head.isSymbolic())
- branchName = CLIText.get().branchDetachedHEAD;
- else {
- branchName = head.getTarget().getName();
- if (branchName.startsWith(Constants.R_HEADS))
- branchName = branchName.substring(Constants.R_HEADS.length());
+ String branchName;
+ if (!head.isSymbolic())
+ branchName = CLIText.get().branchDetachedHEAD;
+ else {
+ branchName = head.getTarget().getName();
+ if (branchName.startsWith(Constants.R_HEADS))
+ branchName = branchName.substring(Constants.R_HEADS.length());
+ }
+ outw.println("[" + branchName + " " + commit.name() + "] " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + commit.getShortMessage());
}
- outw.println("[" + branchName + " " + commit.name() + "] " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + commit.getShortMessage());
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java
index 901e5604ae..ec000f388b 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java
@@ -61,20 +61,21 @@ class Describe extends TextBuiltin {
@Override
protected void run() throws Exception {
- DescribeCommand cmd = new Git(db).describe();
- if (tree != null)
- cmd.setTarget(tree);
- cmd.setLong(longDesc);
- String result = null;
- try {
- result = cmd.call();
- } catch (RefNotFoundException e) {
- throw die(CLIText.get().noNamesFound, e);
- }
- if (result == null)
- throw die(CLIText.get().noNamesFound);
+ try (Git git = new Git(db)) {
+ DescribeCommand cmd = git.describe();
+ if (tree != null)
+ cmd.setTarget(tree);
+ cmd.setLong(longDesc);
+ String result = null;
+ try {
+ result = cmd.call();
+ } catch (RefNotFoundException e) {
+ throw die(CLIText.get().noNamesFound, e);
+ }
+ if (result == null)
+ throw die(CLIText.get().noNamesFound);
- outw.println(result);
+ outw.println(result);
+ }
}
-
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java
index 186fdd8a22..ed06733a44 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java
@@ -104,31 +104,32 @@ class Fetch extends AbstractFetchCommand {
@Override
protected void run() throws Exception {
- Git git = new Git(db);
- FetchCommand fetch = git.fetch();
- if (fsck != null)
- fetch.setCheckFetchedObjects(fsck.booleanValue());
- if (prune != null)
- fetch.setRemoveDeletedRefs(prune.booleanValue());
- if (toget != null)
- fetch.setRefSpecs(toget);
- if (tags != null) {
- fetch.setTagOpt(tags.booleanValue() ? TagOpt.FETCH_TAGS
- : TagOpt.NO_TAGS);
+ try (Git git = new Git(db)) {
+ FetchCommand fetch = git.fetch();
+ if (fsck != null)
+ fetch.setCheckFetchedObjects(fsck.booleanValue());
+ if (prune != null)
+ fetch.setRemoveDeletedRefs(prune.booleanValue());
+ if (toget != null)
+ fetch.setRefSpecs(toget);
+ if (tags != null) {
+ fetch.setTagOpt(tags.booleanValue() ? TagOpt.FETCH_TAGS
+ : TagOpt.NO_TAGS);
+ }
+ if (0 <= timeout)
+ fetch.setTimeout(timeout);
+ fetch.setDryRun(dryRun);
+ fetch.setRemote(remote);
+ if (thin != null)
+ fetch.setThin(thin.booleanValue());
+ if (quiet == null || !quiet.booleanValue())
+ fetch.setProgressMonitor(new TextProgressMonitor(errw));
+
+ FetchResult result = fetch.call();
+ if (result.getTrackingRefUpdates().isEmpty())
+ return;
+
+ showFetchResult(result);
}
- if (0 <= timeout)
- fetch.setTimeout(timeout);
- fetch.setDryRun(dryRun);
- fetch.setRemote(remote);
- if (thin != null)
- fetch.setThin(thin.booleanValue());
- if (quiet == null || !quiet.booleanValue())
- fetch.setProgressMonitor(new TextProgressMonitor(errw));
-
- FetchResult result = fetch.call();
- if (result.getTrackingRefUpdates().isEmpty())
- return;
-
- showFetchResult(result);
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
index 93c4388dbc..fc32d4fcfe 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
@@ -121,22 +121,23 @@ class Merge extends TextBuiltin {
CLIText.get().refDoesNotExistOrNoCommit, ref));
Ref oldHead = db.getRef(Constants.HEAD);
- Git git = new Git(db);
- MergeCommand mergeCmd = git.merge().setStrategy(mergeStrategy)
- .setSquash(squash).setFastForward(ff).setCommit(!noCommit);
- if (srcRef != null)
- mergeCmd.include(srcRef);
- else
- mergeCmd.include(src);
+ MergeResult result;
+ try (Git git = new Git(db)) {
+ MergeCommand mergeCmd = git.merge().setStrategy(mergeStrategy)
+ .setSquash(squash).setFastForward(ff).setCommit(!noCommit);
+ if (srcRef != null)
+ mergeCmd.include(srcRef);
+ else
+ mergeCmd.include(src);
- if (message != null)
- mergeCmd.setMessage(message);
+ if (message != null)
+ mergeCmd.setMessage(message);
- MergeResult result;
- try {
- result = mergeCmd.call();
- } catch (CheckoutConflictException e) {
- result = new MergeResult(e.getConflictingPaths()); // CHECKOUT_CONFLICT
+ try {
+ result = mergeCmd.call();
+ } catch (CheckoutConflictException e) {
+ result = new MergeResult(e.getConflictingPaths()); // CHECKOUT_CONFLICT
+ }
}
switch (result.getMergeStatus()) {
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java
index 4268f214fd..1879ef51ff 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java
@@ -109,24 +109,25 @@ class Push extends TextBuiltin {
@Override
protected void run() throws Exception {
- Git git = new Git(db);
- PushCommand push = git.push();
- push.setDryRun(dryRun);
- push.setForce(force);
- push.setProgressMonitor(new TextProgressMonitor(errw));
- push.setReceivePack(receivePack);
- push.setRefSpecs(refSpecs);
- if (all)
- push.setPushAll();
- if (tags)
- push.setPushTags();
- push.setRemote(remote);
- push.setThin(thin);
- push.setTimeout(timeout);
- Iterable<PushResult> results = push.call();
- for (PushResult result : results) {
- try (ObjectReader reader = db.newObjectReader()) {
- printPushResult(reader, result.getURI(), result);
+ try (Git git = new Git(db)) {
+ PushCommand push = git.push();
+ push.setDryRun(dryRun);
+ push.setForce(force);
+ push.setProgressMonitor(new TextProgressMonitor(errw));
+ push.setReceivePack(receivePack);
+ push.setRefSpecs(refSpecs);
+ if (all)
+ push.setPushAll();
+ if (tags)
+ push.setPushTags();
+ push.setRemote(remote);
+ push.setThin(thin);
+ push.setTimeout(timeout);
+ Iterable<PushResult> results = push.call();
+ for (PushResult result : results) {
+ try (ObjectReader reader = db.newObjectReader()) {
+ printPushResult(reader, result.getURI(), result);
+ }
}
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java
index aa90f8d50c..86a021dee1 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java
@@ -59,13 +59,15 @@ class Reflog extends TextBuiltin {
@Override
protected void run() throws Exception {
- ReflogCommand cmd = new Git(db).reflog();
- if (ref != null)
- cmd.setRef(ref);
- Collection<ReflogEntry> entries = cmd.call();
- int i = 0;
- for (ReflogEntry entry : entries) {
- outw.println(toString(entry, i++));
+ try (Git git = new Git(db)) {
+ ReflogCommand cmd = git.reflog();
+ if (ref != null)
+ cmd.setRef(ref);
+ Collection<ReflogEntry> entries = cmd.call();
+ int i = 0;
+ for (ReflogEntry entry : entries) {
+ outw.println(toString(entry, i++));
+ }
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java
index f4cbcafed1..6d1b1c5481 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java
@@ -66,19 +66,21 @@ class Reset extends TextBuiltin {
@Override
protected void run() throws Exception {
- ResetCommand command = new Git(db).reset();
- command.setRef(commit);
- ResetType mode = null;
- if (soft)
- mode = selectMode(mode, ResetType.SOFT);
- if (mixed)
- mode = selectMode(mode, ResetType.MIXED);
- if (hard)
- mode = selectMode(mode, ResetType.HARD);
- if (mode == null)
- throw die("no reset mode set");
- command.setMode(mode);
- command.call();
+ try (Git git = new Git(db)) {
+ ResetCommand command = git.reset();
+ command.setRef(commit);
+ ResetType mode = null;
+ if (soft)
+ mode = selectMode(mode, ResetType.SOFT);
+ if (mixed)
+ mode = selectMode(mode, ResetType.MIXED);
+ if (hard)
+ mode = selectMode(mode, ResetType.HARD);
+ if (mode == null)
+ throw die("no reset mode set");
+ command.setMode(mode);
+ command.call();
+ }
}
private static ResetType selectMode(ResetType mode, ResetType want) {
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java
index 816b3104c2..f4f864b397 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java
@@ -63,10 +63,11 @@ class Rm extends TextBuiltin {
@Override
protected void run() throws Exception {
- RmCommand command = new Git(db).rm();
- for (String p : paths)
- command.addFilepattern(p);
- command.call();
+ try (Git git = new Git(db)) {
+ RmCommand command = git.rm();
+ for (String p : paths)
+ command.addFilepattern(p);
+ command.call();
+ }
}
-
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java
index 12d4208152..be82d070f7 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java
@@ -88,12 +88,14 @@ class Status extends TextBuiltin {
@Override
protected void run() throws Exception {
- StatusCommand statusCommand = new Git(db).status();
- if (filterPaths != null && filterPaths.size() > 0)
- for (String path : filterPaths)
- statusCommand.addPath(path);
- org.eclipse.jgit.api.Status status = statusCommand.call();
- printStatus(status);
+ try (Git git = new Git(db)) {
+ StatusCommand statusCommand = git.status();
+ if (filterPaths != null && filterPaths.size() > 0)
+ for (String path : filterPaths)
+ statusCommand.addPath(path);
+ org.eclipse.jgit.api.Status status = statusCommand.call();
+ printStatus(status);
+ }
}
private void printStatus(org.eclipse.jgit.api.Status status)
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java
index a90d4c4dad..582094d158 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java
@@ -79,26 +79,27 @@ class Tag extends TextBuiltin {
@Override
protected void run() throws Exception {
- Git git = new Git(db);
- if (tagName != null) {
- TagCommand command = git.tag().setForceUpdate(force)
- .setMessage(message).setName(tagName);
+ try (Git git = new Git(db)) {
+ if (tagName != null) {
+ TagCommand command = git.tag().setForceUpdate(force)
+ .setMessage(message).setName(tagName);
- if (object != null) {
- RevWalk walk = new RevWalk(db);
- command.setObjectId(walk.parseAny(object));
- }
- try {
- command.call();
- } catch (RefAlreadyExistsException e) {
- throw die(MessageFormat.format(CLIText.get().tagAlreadyExists,
- tagName));
- }
- } else {
- ListTagCommand command = git.tagList();
- List<Ref> list = command.call();
- for (Ref ref : list) {
- outw.println(Repository.shortenRefName(ref.getName()));
+ if (object != null) {
+ RevWalk walk = new RevWalk(db);
+ command.setObjectId(walk.parseAny(object));
+ }
+ try {
+ command.call();
+ } catch (RefAlreadyExistsException e) {
+ throw die(MessageFormat.format(CLIText.get().tagAlreadyExists,
+ tagName));
+ }
+ } else {
+ ListTagCommand command = git.tagList();
+ List<Ref> list = command.call();
+ for (Ref ref : list) {
+ outw.println(Repository.shortenRefName(ref.getName()));
+ }
}
}
}