@ -82,6 +82,10 @@ public class PullCommand extends TransportCommand<PullCommand, PullResult> {
private PullRebaseMode pullRebaseMode = PullRebaseMode . USE_CONFIG ;
private PullRebaseMode pullRebaseMode = PullRebaseMode . USE_CONFIG ;
private String remote ;
private String remoteBranchName ;
private enum PullRebaseMode {
private enum PullRebaseMode {
USE_CONFIG ,
USE_CONFIG ,
REBASE ,
REBASE ,
@ -177,21 +181,24 @@ public class PullCommand extends TransportCommand<PullCommand, PullResult> {
JGitText . get ( ) . cannotPullOnARepoWithState , repo
JGitText . get ( ) . cannotPullOnARepoWithState , repo
. getRepositoryState ( ) . name ( ) ) ) ;
. getRepositoryState ( ) . name ( ) ) ) ;
// get the configured remote for the currently checked out branch
// stored in configuration key branch.<branch name>.remote
Config repoConfig = repo . getConfig ( ) ;
Config repoConfig = repo . getConfig ( ) ;
String remote = repoConfig . getString (
if ( remote = = null ) {
ConfigConstants . CONFIG_BRANCH_SECTION , branchName ,
// get the configured remote for the currently checked out branch
ConfigConstants . CONFIG_KEY_REMOTE ) ;
// stored in configuration key branch.<branch name>.remote
remote = repoConfig . getString (
ConfigConstants . CONFIG_BRANCH_SECTION , branchName ,
ConfigConstants . CONFIG_KEY_REMOTE ) ;
}
if ( remote = = null )
if ( remote = = null )
// fall back to default remote
// fall back to default remote
remote = Constants . DEFAULT_REMOTE_NAME ;
remote = Constants . DEFAULT_REMOTE_NAME ;
// get the name of the branch in the remote repository
if ( remoteBranchName = = null )
// stored in configuration key branch.<branch name>.merge
// get the name of the branch in the remote repository
String remoteBranchName = repoConfig . getString (
// stored in configuration key branch.<branch name>.merge
ConfigConstants . CONFIG_BRANCH_SECTION , branchName ,
remoteBranchName = repoConfig . getString (
ConfigConstants . CONFIG_KEY_MERGE ) ;
ConfigConstants . CONFIG_BRANCH_SECTION , branchName ,
ConfigConstants . CONFIG_KEY_MERGE ) ;
// determines whether rebase should be used after fetching
// determines whether rebase should be used after fetching
boolean doRebase = false ;
boolean doRebase = false ;
@ -211,12 +218,8 @@ public class PullCommand extends TransportCommand<PullCommand, PullResult> {
break ;
break ;
}
}
if ( remoteBranchName = = null ) {
if ( remoteBranchName = = null )
String missingKey = ConfigConstants . CONFIG_BRANCH_SECTION + DOT
remoteBranchName = branchName ;
+ branchName + DOT + ConfigConstants . CONFIG_KEY_MERGE ;
throw new InvalidConfigurationException ( MessageFormat . format (
JGitText . get ( ) . missingConfigurationForKey , missingKey ) ) ;
}
final boolean isRemote = ! remote . equals ( "." ) ; //$NON-NLS-1$
final boolean isRemote = ! remote . equals ( "." ) ; //$NON-NLS-1$
String remoteUri ;
String remoteUri ;
@ -309,4 +312,53 @@ public class PullCommand extends TransportCommand<PullCommand, PullResult> {
return result ;
return result ;
}
}
/ * *
* The remote ( uri or name ) to be used for the pull operation . If no remote
* is set , the branch ' s configuration will be used . If the branch
* configuration is missing the default value of
* < code > Constants . DEFAULT_REMOTE_NAME < / code > will be used .
*
* @see Constants # DEFAULT_REMOTE_NAME
* @param remote
* @return { @code this }
* @since 3 . 3
* /
public PullCommand setRemote ( String remote ) {
checkCallable ( ) ;
this . remote = remote ;
return this ;
}
/ * *
* The remote branch name to be used for the pull operation . If no
* remoteBranchName is set , the branch ' s configuration will be used . If the
* branch configuration is missing the remote branch with the same name as
* the current branch is used .
*
* @param remoteBranchName
* @return { @code this }
* @since 3 . 3
* /
public PullCommand setRemoteBranchName ( String remoteBranchName ) {
checkCallable ( ) ;
this . remoteBranchName = remoteBranchName ;
return this ;
}
/ * *
* @return the remote used for the pull operation if it was set explicitly
* @since 3 . 3
* /
public String getRemote ( ) {
return remote ;
}
/ * *
* @return the remote branch name used for the pull operation if it was set
* explicitly
* @since 3 . 3
* /
public String getRemoteBranchName ( ) {
return remoteBranchName ;
}
}
}