@@ -40,28 +40,29 @@ boolean detectDifference(Path projectRoot, String target, String source) throws
4040 throw new IllegalArgumentException ("Git repository not found at " + projectRoot );
4141 }
4242 Path gitRoot = optionalGitRoot .get ();
43- Git git = Git .open (gitRoot .toFile ());
44- Repository repository = git .getRepository ();
45- Ref targetRef = repository .exactRef (target );
46- if (targetRef == null ) {
47- throw new IllegalArgumentException (target + " does not exist in this Git repo" );
48- }
49- Ref sourceRef = repository .exactRef (source );
50- if (sourceRef == null ) {
51- throw new IllegalArgumentException (source + " does not exist in this Git repo" );
43+ try (Git git = Git .open (gitRoot .toFile ())) {
44+ Repository repository = git .getRepository ();
45+ Ref targetRef = repository .exactRef (target );
46+ if (targetRef == null ) {
47+ throw new IllegalArgumentException (target + " does not exist in this Git repo" );
48+ }
49+ Ref sourceRef = repository .exactRef (source );
50+ if (sourceRef == null ) {
51+ throw new IllegalArgumentException (source + " does not exist in this Git repo" );
52+ }
53+ return !sourceRef .equals (targetRef );
5254 }
53- return !sourceRef .equals (targetRef );
5455 }
5556
56- Stream <Path > detectUpdatedCode (Path projectRoot , String target , String source ) throws IOException {
57+ Stream <Path > detectUpdatedCode (Path projectRoot , String target , String source )
58+ throws IOException {
5759 Optional <Path > optionalGitRoot = findGitRoot (projectRoot );
5860 if (!optionalGitRoot .isPresent ()) {
5961 throw new IllegalArgumentException ("Git repository not found at " + projectRoot );
6062 }
6163
62- try {
63- Path gitRoot = optionalGitRoot .get ();
64- Git git = Git .open (gitRoot .toFile ());
64+ Path gitRoot = optionalGitRoot .get ();
65+ try (Git git = Git .open (gitRoot .toFile ())) {
6566 Repository repository = git .getRepository ();
6667 List <DiffEntry > updated =
6768 git .diff ()
0 commit comments