@@ -84,29 +84,13 @@ public String getBuildAuthorEmail() throws GitCommitIdExecutionException {
8484 @ Override
8585 public void prepareGitToExtractMoreDetailedRepoInformation () throws GitCommitIdExecutionException {
8686 try {
87- // more details parsed out bellow
88- Ref evaluateOnCommitReference = git .findRef (evaluateOnCommit );
89- ObjectId evaluateOnCommitResolvedObjectId = git .resolve (evaluateOnCommit );
90-
91- if ((evaluateOnCommitReference == null ) && (evaluateOnCommitResolvedObjectId == null )) {
92- throw new GitCommitIdExecutionException (
93- "Could not get " + evaluateOnCommit + " Ref, are you sure you have set the dotGitDirectory " +
94- "property of this plugin to a valid path (currently set to " + dotGitDirectory + ")?" );
95- }
87+ // more details parsed out below
9688 revWalk = new RevWalk (git );
97- ObjectId headObjectId ;
98- if (evaluateOnCommitReference != null ) {
99- headObjectId = evaluateOnCommitReference .getObjectId ();
89+ if (perModuleVersions && moduleBaseDir != null ) {
90+ evalCommit = getCommitFromModuleDirectory (moduleBaseDir );
10091 } else {
101- headObjectId = evaluateOnCommitResolvedObjectId ;
92+ evalCommit = getCommitFromRef () ;
10293 }
103-
104- if (headObjectId == null ) {
105- throw new GitCommitIdExecutionException (
106- "Could not get " + evaluateOnCommit + " Ref, are you sure you have some " +
107- "commits in the dotGitDirectory (currently set to " + dotGitDirectory + ")?" );
108- }
109- evalCommit = revWalk .parseCommit (headObjectId );
11094 revWalk .markStart (evalCommit );
11195 } catch (GitCommitIdExecutionException e ) {
11296 throw e ;
@@ -115,6 +99,54 @@ public void prepareGitToExtractMoreDetailedRepoInformation() throws GitCommitIdE
11599 }
116100 }
117101
102+ private RevCommit getCommitFromModuleDirectory (File moduleBaseDir ) throws GitAPIException , GitCommitIdExecutionException {
103+ //retrieve last commit in folder moduleBaseDir
104+ try (Git gitInstance = new Git (git )) {
105+ String relativePath = git .getDirectory ().getParentFile ().toPath ().relativize (moduleBaseDir .getAbsoluteFile ().toPath ()).toString ();
106+ Iterator <RevCommit > iterator = gitInstance .log ()
107+ .addPath (relativePath ).call ().iterator ();
108+ if (!iterator .hasNext ()) {
109+ throw new GitCommitIdExecutionException (
110+ "Could not get commit from folder " + relativePath + " , are you sure you have some " +
111+ "commits in the folder " + moduleBaseDir + "?" );
112+ }
113+
114+ RevCommit revCommit = iterator .next ();
115+ if (revCommit == null ) {
116+ throw new GitCommitIdExecutionException (
117+ "Could not get commit from folder " + relativePath +
118+ " , are you sure you have some commits in the folder " + moduleBaseDir + "?" );
119+ }
120+
121+ return revCommit ;
122+ }
123+ }
124+
125+ private RevCommit getCommitFromRef () throws IOException , GitCommitIdExecutionException {
126+ // more details parsed out below
127+ Ref evaluateOnCommitReference = git .findRef (evaluateOnCommit );
128+ ObjectId evaluateOnCommitResolvedObjectId = git .resolve (evaluateOnCommit );
129+
130+ if ((evaluateOnCommitReference == null ) && (evaluateOnCommitResolvedObjectId == null )) {
131+ throw new GitCommitIdExecutionException (
132+ "Could not get " + evaluateOnCommit + " Ref, are you sure you have set the dotGitDirectory " +
133+ "property of this plugin to a valid path (currently set to " + dotGitDirectory + ")?" );
134+ }
135+ ObjectId headObjectId ;
136+ if (evaluateOnCommitReference != null ) {
137+ headObjectId = evaluateOnCommitReference .getObjectId ();
138+ } else {
139+ headObjectId = evaluateOnCommitResolvedObjectId ;
140+ }
141+
142+ if (headObjectId == null ) {
143+ throw new GitCommitIdExecutionException (
144+ "Could not get " + evaluateOnCommit + " Ref, are you sure you have some " +
145+ "commits in the dotGitDirectory (currently set to " + dotGitDirectory + ")?" );
146+ }
147+ return revWalk .parseCommit (headObjectId );
148+ }
149+
118150 @ Override
119151 public String getBranchName () throws GitCommitIdExecutionException {
120152 try {
0 commit comments