@ -128,7 +128,7 @@ public class CheckoutCommand extends GitCommand<Ref> {
String refLogMessage = "checkout: moving from "
String refLogMessage = "checkout: moving from "
+ headRef . getTarget ( ) . getName ( ) ;
+ headRef . getTarget ( ) . getName ( ) ;
ObjectId branch = repo . resolve ( name ) ;
ObjectId branch = repo . resolve ( name ) ;
Ref ref = repo . getRef ( name ) ;
if ( branch = = null )
if ( branch = = null )
throw new RefNotFoundException ( MessageFormat . format ( JGitText
throw new RefNotFoundException ( MessageFormat . format ( JGitText
. get ( ) . refNotResolved , name ) ) ;
. get ( ) . refNotResolved , name ) ) ;
@ -148,11 +148,20 @@ public class CheckoutCommand extends GitCommand<Ref> {
status = new CheckoutResult ( Status . CONFLICTS , fileList ) ;
status = new CheckoutResult ( Status . CONFLICTS , fileList ) ;
throw e ;
throw e ;
}
}
RefUpdate refUpdate = repo . updateRef ( Constants . HEAD ) ;
Ref ref = repo . getRef ( name ) ;
if ( ref ! = null & & ! ref . getName ( ) . startsWith ( Constants . R_HEADS ) )
ref = null ;
RefUpdate refUpdate = repo . updateRef ( Constants . HEAD , ref = = null ) ;
refUpdate . setForceUpdate ( force ) ;
refUpdate . setForceUpdate ( force ) ;
refUpdate . setRefLogMessage ( refLogMessage + "to "
refUpdate . setRefLogMessage ( refLogMessage + "to "
+ newCommit . getName ( ) , false ) ;
+ newCommit . getName ( ) , false ) ;
Result updateResult = refUpdate . link ( ref . getName ( ) ) ;
Result updateResult ;
if ( ref ! = null )
updateResult = refUpdate . link ( ref . getName ( ) ) ;
else {
refUpdate . setNewObjectId ( newCommit ) ;
updateResult = refUpdate . forceUpdate ( ) ;
}
setCallable ( false ) ;
setCallable ( false ) ;
@ -174,8 +183,6 @@ public class CheckoutCommand extends GitCommand<Ref> {
throw new JGitInternalException ( MessageFormat . format ( JGitText
throw new JGitInternalException ( MessageFormat . format ( JGitText
. get ( ) . checkoutUnexpectedResult , updateResult . name ( ) ) ) ;
. get ( ) . checkoutUnexpectedResult , updateResult . name ( ) ) ) ;
Ref result = repo . getRef ( name ) ;
if ( ! repo . isBare ( ) & & ! dco . getToBeDeleted ( ) . isEmpty ( ) ) {
if ( ! repo . isBare ( ) & & ! dco . getToBeDeleted ( ) . isEmpty ( ) ) {
List < File > fileList = new ArrayList < File > ( ) ;
List < File > fileList = new ArrayList < File > ( ) ;
for ( String filePath : dco . getToBeDeleted ( ) ) {
for ( String filePath : dco . getToBeDeleted ( ) ) {
@ -185,7 +192,7 @@ public class CheckoutCommand extends GitCommand<Ref> {
}
}
else
else
status = CheckoutResult . OK_RESULT ;
status = CheckoutResult . OK_RESULT ;
return result ;
return ref ;
} catch ( IOException ioe ) {
} catch ( IOException ioe ) {
throw new JGitInternalException ( ioe . getMessage ( ) , ioe ) ;
throw new JGitInternalException ( ioe . getMessage ( ) , ioe ) ;
} finally {
} finally {