Community
Participate
Working Groups
1. Create two clones of the same repo 2. Make sure they have at least two remote branches and that they're in sync 3. In the first clone, make changes on both branches and commit them, do not push yet 4. do "git push remote_name" Git git = new Git(db); git.push().setRemote(remote).call(); => SHOULD BE: changes from both branches should be pushed (like in Git Bash). => IS: only HEAD branch is pushed. probably caused by that lines: PushCommand.call() { [ ... ] if (refSpecs.isEmpty()) { RemoteConfig config = new RemoteConfig(repo.getConfig(), getRemote()); refSpecs.addAll(config.getPushRefSpecs()); } if (refSpecs.isEmpty()) { Ref head = repo.getRef(Constants.HEAD); if (head != null && head.isSymbolic()) refSpecs.add(new RefSpec(head.getLeaf().getName())); } [...]
In other words, if a branch exists remotely there is no need to specify a refspec or use --all flag to push its changes. In cgit, doing "git push <remote>" is enough to push commits from all branches. Workaround: if you're not setting a refspec to push, don't forget to call PushCommand.setPushAll().
A failing test case: http://egit.eclipse.org/r/4022
A fix has been proposed on http://egit.eclipse.org/r/#change,4022.
Ping. Could someone from the JGit team review the suggested fix, please.
https://git.eclipse.org/r/#/c/4022/ has been rebased, still waiting for a comment.
By the way, C Git is discussing a change of what "git push" without arguments should actually do (matching, upstream, current): https://lwn.net/Articles/487131/ I don't know what the current state of the discussion is, but we should probably follow the decision in JGit.
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/190980
(In reply to Eclipse Genie from comment #7) > New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/190980 The default value for push.default is nowadays "simple". JGit has traditionally implemented "current", and that is still the default for PushCommand. PushCommand has gotten a setPushDefault() operation to set an explicit mode, though, that would be used if no RefSpecs are given. setPushDefault(null) would make it use the git config. setPushAll() as mentioned in comment 1 is not a valid work-around, it would also push local branches for which the remote has no corresponding branch yet. The above change implements the ":" and "+:" RefSpecs, and uses ":" if a push.default of "matching" is active and no RefSpec was given. (It'll also use it if given explicitly.)
Gerrit change https://git.eclipse.org/r/c/jgit/jgit/+/190980 was merged to [stable-6.1]. Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=8a2c76941729629dce06e2238464e114f2ccc79a