mattcasters commented on code in PR #8974:
URL: https://github.com/apache/hop/pull/8974#discussion_r4435533611
##########
plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java:
##########
@@ -795,12 +795,37 @@ public boolean pull() throws HopException {
} else {
throw new HopException("There was an error doing a git pull", e);
}
+ } catch (HopException e) {
+ throw e;
} catch (Exception e) {
throw new HopException("There was an error doing a git pull", e);
}
return false;
}
+ private String getPullBranch() throws HopException, IOException {
+ Repository repository = git.getRepository();
+ String branch = getBranch();
+ String trackingBranch = new BranchConfig(repository.getConfig(),
branch).getTrackingBranch();
+ String pullBranch =
+ trackingBranch == null
Review Comment:
**[bug]** `BranchConfig.getTrackingBranch()` returns null both when
`branch.<name>.merge` is unset and when an upstream is configured but no fetch
refspec maps it (`findRemoteTrackingBranch` returns null). A single-branch
clone is the usual case: `remote.origin.fetch` is
`+refs/heads/main:refs/remotes/origin/main` while `branch.my-feature.merge` is
`refs/heads/feature-123`. This branch then pretends there is no upstream and
merges `origin/<local-branch>` when that ref exists, or reports that upstream
is not configured when it is.
**Suggestion:** Treat upstream as missing only when `getMerge()` is null. If
merge is set, build the pull ref from the configured remote and
`Repository.shortenRefName(getMerge())` (or the local branch when the remote is
`.`) instead of falling back to `origin/<local-branch>`. Add a test whose fetch
refspec does not match the configured merge ref.
##########
plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java:
##########
@@ -774,8 +775,7 @@ public boolean pull() throws HopException {
try {
// Pull = Fetch + Merge
git.fetch().setCredentialsProvider(credentialsProvider).call();
Review Comment:
**[bug]** `git.fetch()` with no remote still fetches only `origin`, then the
new code merges whatever `getPullBranch()` returns. When `branch.<name>.remote`
is not `origin`, that tracking ref is not updated by this fetch. A stale
`upstream/<branch>` is merged and `pull()` can return true. When the remote is
`.`, the origin fetch is unnecessary and a transport failure blocks a purely
local merge. Previously this method at least merged the ref it had just fetched.
**Suggestion:** Read the remote from `BranchConfig` (default `origin`). Skip
the fetch when it is `.`. Otherwise call
`git.fetch().setRemote(remote).setCredentialsProvider(credentialsProvider).call()`
before resolving the tracking ref. `hasRemote()` still requires a remote named
`origin` even if the branch tracks a different remote.
##########
plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java:
##########
@@ -795,12 +795,37 @@ public boolean pull() throws HopException {
} else {
throw new HopException("There was an error doing a git pull", e);
}
+ } catch (HopException e) {
+ throw e;
} catch (Exception e) {
throw new HopException("There was an error doing a git pull", e);
}
return false;
}
+ private String getPullBranch() throws HopException, IOException {
+ Repository repository = git.getRepository();
+ String branch = getBranch();
Review Comment:
**[suggestion]** `getBranch()` is a UI label. On a detached HEAD it returns
`HEAD detached at <7-char-sha>`, and on any error it returns `""`. Using that
string as the `BranchConfig` section name and as the `origin/<branch>` fallback
cannot find a real upstream and produces a nonsense error. `git pull` on a
detached HEAD says you are not on a branch.
**Suggestion:** Use `repository.exactRef(Constants.HEAD)` /
`getFullBranch()`. If HEAD is not under `refs/heads/`, throw a clear
`HopException` and do not build a pull ref from the display string.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]