|
|
|
@ -89,47 +89,49 @@ class Checkout extends TextBuiltin {
|
|
|
|
|
throw die(CLIText.get().onBranchToBeBorn); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CheckoutCommand command = new Git(db).checkout(); |
|
|
|
|
if (paths.size() > 0) { |
|
|
|
|
command.setStartPoint(name); |
|
|
|
|
for (String path : paths) |
|
|
|
|
command.addPath(path); |
|
|
|
|
} else { |
|
|
|
|
command.setCreateBranch(createBranch); |
|
|
|
|
command.setName(name); |
|
|
|
|
command.setForce(force); |
|
|
|
|
command.setOrphan(orphan); |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
String oldBranch = db.getBranch(); |
|
|
|
|
Ref ref = command.call(); |
|
|
|
|
if (ref == null) |
|
|
|
|
return; |
|
|
|
|
if (Repository.shortenRefName(ref.getName()).equals(oldBranch)) { |
|
|
|
|
try (Git git = new Git(db)) { |
|
|
|
|
CheckoutCommand command = git.checkout(); |
|
|
|
|
if (paths.size() > 0) { |
|
|
|
|
command.setStartPoint(name); |
|
|
|
|
for (String path : paths) |
|
|
|
|
command.addPath(path); |
|
|
|
|
} else { |
|
|
|
|
command.setCreateBranch(createBranch); |
|
|
|
|
command.setName(name); |
|
|
|
|
command.setForce(force); |
|
|
|
|
command.setOrphan(orphan); |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
String oldBranch = db.getBranch(); |
|
|
|
|
Ref ref = command.call(); |
|
|
|
|
if (ref == null) |
|
|
|
|
return; |
|
|
|
|
if (Repository.shortenRefName(ref.getName()).equals(oldBranch)) { |
|
|
|
|
outw.println(MessageFormat.format( |
|
|
|
|
CLIText.get().alreadyOnBranch, |
|
|
|
|
name)); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (createBranch || orphan) |
|
|
|
|
outw.println(MessageFormat.format( |
|
|
|
|
CLIText.get().switchedToNewBranch, name)); |
|
|
|
|
else |
|
|
|
|
outw.println(MessageFormat.format( |
|
|
|
|
CLIText.get().switchedToBranch, |
|
|
|
|
Repository.shortenRefName(ref.getName()))); |
|
|
|
|
} catch (RefNotFoundException e) { |
|
|
|
|
outw.println(MessageFormat.format( |
|
|
|
|
CLIText.get().alreadyOnBranch, |
|
|
|
|
CLIText.get().pathspecDidNotMatch, |
|
|
|
|
name)); |
|
|
|
|
} catch (RefAlreadyExistsException e) { |
|
|
|
|
throw die(MessageFormat.format(CLIText.get().branchAlreadyExists, |
|
|
|
|
name)); |
|
|
|
|
return; |
|
|
|
|
} catch (CheckoutConflictException e) { |
|
|
|
|
outw.println(CLIText.get().checkoutConflict); |
|
|
|
|
for (String path : e.getConflictingPaths()) |
|
|
|
|
outw.println(MessageFormat.format( |
|
|
|
|
CLIText.get().checkoutConflictPathLine, path)); |
|
|
|
|
} |
|
|
|
|
if (createBranch || orphan) |
|
|
|
|
outw.println(MessageFormat.format( |
|
|
|
|
CLIText.get().switchedToNewBranch, name)); |
|
|
|
|
else |
|
|
|
|
outw.println(MessageFormat.format( |
|
|
|
|
CLIText.get().switchedToBranch, |
|
|
|
|
Repository.shortenRefName(ref.getName()))); |
|
|
|
|
} catch (RefNotFoundException e) { |
|
|
|
|
outw.println(MessageFormat.format( |
|
|
|
|
CLIText.get().pathspecDidNotMatch, |
|
|
|
|
name)); |
|
|
|
|
} catch (RefAlreadyExistsException e) { |
|
|
|
|
throw die(MessageFormat.format(CLIText.get().branchAlreadyExists, |
|
|
|
|
name)); |
|
|
|
|
} catch (CheckoutConflictException e) { |
|
|
|
|
outw.println(CLIText.get().checkoutConflict); |
|
|
|
|
for (String path : e.getConflictingPaths()) |
|
|
|
|
outw.println(MessageFormat.format( |
|
|
|
|
CLIText.get().checkoutConflictPathLine, path)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|