Skip to content

Commit

Permalink
Improve commit message (#934)
Browse files Browse the repository at this point in the history
### Motivation
When unspecified a branch name on mirroring setup, the message show with `#null`, we should omit #null when using the default branch to avoid confuse.

Result
Close: #933
  • Loading branch information
thachlp committed Jun 13, 2024
1 parent cb0b130 commit 138eb29
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ void remoteToLocal() throws Exception {

@Test
void remoteToLocal_gitignore() throws Exception {
pushMirrorSettings(null, "/first", "\"/exclude_if_root.txt\\nexclude_dir\"");
pushMirrorSettings(null, "/first#master", "\"/exclude_if_root.txt\\nexclude_dir\"");
checkGitignore();
}

@Test
void remoteToLocal_gitignore_with_array() throws Exception {
pushMirrorSettings(null, "/first", "[\"/exclude_if_root.txt\", \"exclude_dir\"]");
pushMirrorSettings(null, "/first#master", "[\"/exclude_if_root.txt\", \"exclude_dir\"]");
checkGitignore();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ void mirrorRemoteToLocal(
changes.put(mirrorStatePath, Change.ofJsonUpsert(
mirrorStatePath, "{ \"sourceRevision\": \"" + headCommitId.name() + "\" }"));
// Construct the log message and log.
summary = "Mirror " + abbrId + ", " + remoteRepoUri() + '#' + remoteBranch() +
" to the repository '" + localRepo().name() + '\'';
final String branchName = getRemoteBranchName(headBranchRef);
summary = "Mirror " + abbrId + ", '" + remoteRepoUri() + '#' + branchName +
"' to the repository '" + localRepo().name() + '\'';
final RevCommit headCommit = revWalk.parseCommit(headCommitId);
detail = generateCommitDetail(headCommit);
logger.info(summary);
Expand Down Expand Up @@ -723,6 +724,18 @@ static void updateRef(org.eclipse.jgit.lib.Repository jGitRepository, RevWalk re
}
}

private String getRemoteBranchName(Ref headBranchRef) {
final String remoteBranch = remoteBranch();
if (remoteBranch != null && !remoteBranch.isEmpty()) {
return remoteBranch;
}
final String headBranchName = headBranchRef.getName();
if (headBranchName.startsWith(Constants.R_HEADS)) {
return headBranchName.substring(Constants.R_HEADS.length());
}
return headBranchName;
}

private static final class InsertText extends PathEdit {
private final ObjectInserter inserter;
private final String text;
Expand Down

0 comments on commit 138eb29

Please sign in to comment.