Skip to content

Commit 544a400

Browse files
committed
CmdCheckout -ls option - shows current branch\commit name
CmdCheckout -s option passthrough to CmdRestore CmdClone -directory option to select clone subdirectory
1 parent 610577c commit 544a400

3 files changed

Lines changed: 38 additions & 18 deletions

File tree

src/main/java/ru/fusionsoft/dbgit/command/CmdCheckout.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ public void execute(CommandLine cmdLine) throws Exception {
5757

5858
if (cmdLine.hasOption("ls")){
5959
try(RevWalk walk = new RevWalk(repo)){
60+
String branch = repo.getBranch();
61+
String headNumber = head.getObjectId().getName();
62+
String headName = head.getName();
63+
String message = walk.parseCommit(head.getObjectId()).getShortMessage();
64+
6065
ConsoleWriter.printlnGreen(MessageFormat.format(
61-
"{0}: {1} ({2}) - {3}",
62-
repo.getBranch(), head.getObjectId().getName(), head.getName(),
63-
walk.parseCommit(head.getObjectId()).getShortMessage()
66+
"{0} ({1}) {2}",
67+
!branch.equals(headNumber) ? branch + ": " + headName : headNumber,
68+
headName,
69+
message
6470
));
6571
}
6672
return;
@@ -96,6 +102,11 @@ public void execute(CommandLine cmdLine) throws Exception {
96102
if (cmdLine.hasOption("v")) {
97103
builder.addOption(new Option("v", false, ""));
98104
}
105+
if (cmdLine.hasOption("s")) {
106+
Option scriptOption = new Option("s", true, "");
107+
scriptOption.getValuesList().add(cmdLine.getOptionValue("s"));
108+
builder.addOption(scriptOption);
109+
}
99110

100111
restoreCommand.execute(builder.build());
101112
}

src/main/java/ru/fusionsoft/dbgit/command/CmdClone.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
import ru.fusionsoft.dbgit.core.DBGit;
77
import ru.fusionsoft.dbgit.core.ExceptionDBGit;
88

9+
import java.io.File;
10+
911
public class CmdClone implements IDBGitCommand {
1012

1113
private Options opts = new Options();
12-
14+
15+
public CmdClone() {
16+
opts.addOption("directory", false, "subdirectory to clone into"/*getLang().getValue("help", "commit-a").toString()*/);
17+
}
18+
1319
@Override
1420
public String getCommandName() {
1521
return "clone";
@@ -36,6 +42,7 @@ public void execute(CommandLine cmdLine) throws Exception {
3642

3743
String link = "";
3844
String remote = "";
45+
File directory = cmdLine.hasOption("directory") ? new File(cmdLine.getOptionValue("directory")) : null;
3946
if (args.length > 2) {
4047
throw new ExceptionDBGit(getLang().getValue("errors", "paramsNumberIncorrect"));
4148
} else if (args.length == 1) {
@@ -45,7 +52,7 @@ public void execute(CommandLine cmdLine) throws Exception {
4552
remote = args[1];
4653
}
4754

48-
DBGit.gitClone(link, remote);
55+
DBGit.gitClone(link, remote, directory);
4956

5057
}
5158

src/main/java/ru/fusionsoft/dbgit/core/DBGit.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,9 @@
55
import java.util.List;
66
import java.util.Set;
77

8-
import org.eclipse.jgit.api.CheckoutCommand;
9-
import org.eclipse.jgit.api.FetchCommand;
10-
import org.eclipse.jgit.api.Git;
11-
import org.eclipse.jgit.api.InitCommand;
8+
import org.eclipse.jgit.api.*;
129
import org.eclipse.jgit.api.ListBranchCommand.ListMode;
13-
import org.eclipse.jgit.api.MergeCommand;
14-
import org.eclipse.jgit.api.MergeResult;
15-
import org.eclipse.jgit.api.PullCommand;
16-
import org.eclipse.jgit.api.RemoteAddCommand;
17-
import org.eclipse.jgit.api.RemoteRemoveCommand;
1810
import org.eclipse.jgit.api.ResetCommand.ResetType;
19-
import org.eclipse.jgit.api.Status;
2011
import org.eclipse.jgit.dircache.DirCache;
2112
import org.eclipse.jgit.lib.Constants;
2213
import org.eclipse.jgit.lib.Ref;
@@ -370,10 +361,17 @@ public static void gitInit(String dirPath) throws ExceptionDBGit {
370361
}
371362
}
372363

373-
public static void gitClone(String link, String remoteName) throws ExceptionDBGit {
364+
public static void gitClone(String link, String remoteName, File directory) throws ExceptionDBGit {
374365
try {
375-
Git.cloneRepository().setURI(link).setCredentialsProvider(getCredentialsProvider(link))
376-
.setRemote(remoteName.equals("") ? Constants.DEFAULT_REMOTE_NAME : remoteName).call();
366+
String actualRemoteName = remoteName.equals("") ? Constants.DEFAULT_REMOTE_NAME : remoteName;
367+
CredentialsProvider cp = getCredentialsProvider(link);
368+
CloneCommand cc = Git.cloneRepository()
369+
.setURI(link)
370+
.setRemote(actualRemoteName)
371+
.setCredentialsProvider(cp)
372+
.setDirectory(directory);
373+
374+
cc.call();
377375

378376
ConsoleWriter.println(DBGitLang.getInstance().getValue("general", "clone", "cloned"));
379377

@@ -499,6 +497,10 @@ private static CredentialsProvider getCredentialsProvider(String link) throws Ex
499497
500498
ConsoleWriter.detailsPrintLn("login: " + login);
501499
ConsoleWriter.detailsPrintLn("pass: " + pass);*/
500+
if(uri.getUser() == null) {
501+
ConsoleWriter.detailsPrintlnRed(DBGitLang.getInstance().getValue("errors", "gitLoginNotFound"));
502+
return null;
503+
}
502504
return new UsernamePasswordCredentialsProvider(uri.getUser(), uri.getPass());
503505
} catch (Exception e) {
504506
throw new ExceptionDBGit(e);

0 commit comments

Comments
 (0)