[DEV] continue portage

This commit is contained in:
Edouard DUPIN 2021-09-26 23:27:52 +02:00
parent 9fae154bcd
commit 9d0ea8000e
29 changed files with 571 additions and 1129 deletions

View File

@ -1,12 +1,15 @@
package org.atriasoft.island;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.DeltaBranch;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ListBranchCommand.ListMode;
@ -14,6 +17,7 @@ import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.errors.RevisionSyntaxException;
import org.eclipse.jgit.lib.BranchConfig;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
@ -22,8 +26,8 @@ import org.eclipse.jgit.revwalk.RevCommit;
public class Commands {
private Commands() {}
public static List<String> get_list_branch_local(final Git git) throws GitAPIException {
List<String> remotes = Commands.get_list_branch_remote(git);
public static List<String> getListBranchLocal(final Git git) throws GitAPIException {
List<String> remotes = Commands.getListBranchRemote(git);
List<Ref> list_branch_local = git.branchList().setListMode(ListMode.ALL).call();
List<String> out = new ArrayList<>();
for (Ref elem1 : list_branch_local) {
@ -33,7 +37,7 @@ public class Commands {
}
return out;
}
public static List<String> get_list_branch_all(final Git git) throws GitAPIException {
public static List<String> getListBranchAll(final Git git) throws GitAPIException {
List<Ref> list_branch_local = git.branchList().setListMode(ListMode.ALL).call();
List<String> out = new ArrayList<>();
for (Ref elem1 : list_branch_local) {
@ -42,7 +46,7 @@ public class Commands {
return out;
}
public static List<String> get_list_branch_remote(final Git git) throws GitAPIException {
public static List<String> getListBranchRemote(final Git git) throws GitAPIException {
List<Ref> list_branch_local = git.branchList().setListMode(ListMode.REMOTE).call();
List<String> out = new ArrayList<>();
for (Ref elem1 : list_branch_local) {
@ -62,7 +66,7 @@ public class Commands {
public static String get_current_branch(final Git git) throws GitAPIException {
return null;
}
public static List<String> get_tags(final Git git) throws GitAPIException {
public static List<String> getTags(final Git git) throws GitAPIException {
List<Ref> list_tag = git.tagList().call();
List<String> out = new ArrayList<>();
for (Ref elem1 : list_tag) {
@ -70,29 +74,36 @@ public class Commands {
}
return out;
}
public static String get_tracking_branch(final Git git, final String remote_name, final String select_branch) throws GitAPIException, IOException {
public static String getTrackingBranch(final Git git, final String remote_name, final String select_branch) throws GitAPIException, IOException {
// get tracking branch
if (remote_name == null || remote_name.isEmpty()) {
return Commands.get_current_tracking_branch(git);
return Commands.getCurrentTrackingBranch(git);
}
List<String> list_branch_remote = Commands.get_list_branch_remote(git);
List<String> list_branch_remote = Commands.getListBranchRemote(git);
Log.verbose("check if exist " + remote_name + "/" + select_branch + " in " + list_branch_remote);
String tmpBranchName = remote_name + "/" + select_branch;
if (!list_branch_remote.contains(tmpBranchName)) {
if (!list_branch_remote.contains("refs/remotes/" + tmpBranchName)) {
Log.debug(" ==> can not get remote branch");
return null;
}
return remote_name + "/" + select_branch;
}
public static String get_current_tracking_branch(final Git git) throws IOException {
public static String getCurrentTrackingBranch(final Git git) throws IOException {
Repository repo = git.getRepository();
return new BranchConfig(repo.getConfig(), repo.getBranch()).getTrackingBranch();
}
public static List<ObjectId> get_revision_list_to_branch(final Git git, final String branch) throws NoHeadException, GitAPIException {
Iterable<RevCommit> commits = git.log().call();
public static List<ObjectId> getRevisionListToBranch(final Git git, final String branch) throws NoHeadException, GitAPIException {
List<ObjectId> out = new ArrayList<>();
Iterable<RevCommit> commits;
try {
commits = git.log().add(git.getRepository().resolve(branch)).call();
} catch (RevisionSyntaxException | GitAPIException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return out;
}
for(RevCommit commit : commits ) {
ObjectId tmp = commit.toObjectId();
out.add(tmp);
@ -100,7 +111,7 @@ public class Commands {
return out;
}
public static List<String> get_tags_current(final Git git) {
public static List<String> getTagsCurrent(final Git git) {
List<String> out = new ArrayList<>();
RevCommit latestCommit;
try {
@ -133,7 +144,7 @@ public class Commands {
}
return out;
}
public static void get_diff(final Git git) {
public static void getDiff(final Git git) {
try {
Status status = git.status().call();
if (status.getAdded().size() != 0) {
@ -154,14 +165,12 @@ public class Commands {
Log.print(" - " + elem);
}
}
/*
if (status.getIgnoredNotInIndex().size() != 0) {
Log.print(" * Ignored not in index: (" + status.getIgnoredNotInIndex().size() + ")");
for (String elem : status.getIgnoredNotInIndex()) {
Log.print(" - " + elem);
}
}
*/
if (status.getMissing().size() != 0) {
Log.print(" * Missing: (" + status.getMissing().size() + ")");
for (String elem : status.getMissing()) {
@ -197,5 +206,64 @@ public class Commands {
e.printStackTrace();
}
}
/**
* Check if it is a Git repository with checking if the path exist and if the .git path exist.
* @param path Path to check the git repository existence.
* @return true if it is a git repository, false otherwise.
*/
public static boolean isGitRepository(final String path) {
Path git_repo_path = Env.get_island_root_path().resolve(path);
if (!Files.exists(git_repo_path)) {
Log.warning("Path Does not Exist ... " + git_repo_path + " ==> skip");
return false;
}
if (!Files.exists(git_repo_path.resolve(".git"))) {
// path already exist but it is not used to as a git repo ==> this is an error
Log.warning("path '" + git_repo_path + "' Not a git repository ==> skip");
return false;
}
return true;
}
/**
* Get deltas between 2 branches.
* @param git JGit interface of the current repository.
* @param branch1 Name of the branch 1.
* @param branch2 Name of the Branch 2.
* @return The value of behind and forward of the 2 branches
* @throws IOException
* @throws GitAPIException
*/
public static DeltaBranch getDeltaBranch(final Git git, final String branch1, final String branch2) throws IOException, GitAPIException {
List<ObjectId> retCurrentBranchSha1 = getRevisionListToBranch(git, branch1);
List<ObjectId> retTrackBranchSha1 = getRevisionListToBranch(git, branch2);
// remove all identical sha1 ==> not needed for this
int inForward = 0;
for (ObjectId elemSha1 : retCurrentBranchSha1) {
boolean find = false;
for (ObjectId elemSha2 : retTrackBranchSha1) {
if (elemSha2.equals(elemSha1)) {
find = true;
break;
}
}
if (!find) {
inForward++;
}
}
int inBehind = 0;
for (ObjectId elemSha1 : retTrackBranchSha1) {
boolean find = false;
for (ObjectId elemSha2 : retCurrentBranchSha1) {
if (elemSha2.equals(elemSha1)) {
find = true;
break;
}
}
if (!find) {
inBehind++;
}
}
return new DeltaBranch(inForward, inBehind);
}
}

View File

@ -129,7 +129,7 @@ public class Env {
return Env.island_path_config;
}
public static Path get_island_path_manifest() {
public static Path getIslandPathManifest() {
return Env.island_path_manifest;
}
public static Path get_island_path_user_config() {

View File

@ -9,9 +9,15 @@ import org.atriasoft.death.annotation.ArgDescription;
import org.atriasoft.death.annotation.ArgName;
import org.atriasoft.death.annotation.ArgSubActions;
import org.atriasoft.island.actions.Checkout;
import org.atriasoft.island.actions.Commit;
import org.atriasoft.island.actions.Fetch;
import org.atriasoft.island.actions.Init;
import org.atriasoft.island.actions.Push;
import org.atriasoft.island.actions.Status;
import org.atriasoft.island.actions.Sync;
import org.atriasoft.island.actions.VolatileAdd;
import org.atriasoft.island.actions.VolatileList;
import org.atriasoft.island.actions.VolatileRemove;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.ActionException;
@ -62,6 +68,12 @@ public class MainIsland {
MainConfig.subActions.add(Status.class);
MainConfig.subActions.add(Checkout.class);
MainConfig.subActions.add(Sync.class);
MainConfig.subActions.add(Fetch.class);
MainConfig.subActions.add(Commit.class);
MainConfig.subActions.add(Push.class);
MainConfig.subActions.add(VolatileAdd.class);
MainConfig.subActions.add(VolatileRemove.class);
MainConfig.subActions.add(VolatileList.class);
}
public boolean check_boolean(final String value) {
@ -81,50 +93,6 @@ public class MainIsland {
}
}
/*
void run(final String[] args) throws ActionException {
List<String> argss = Arrays.asList(args);
List<ArgElement> local_argument = this.my_args.parse(argss);
// parse default unique argument:
for (ArgElement argument : local_argument) {
parse_generic_arg(argument, true);
}
// remove all generic arguments:
List<ArgElement> new_argument_list = new ArrayList<>();
for (ArgElement argument : local_argument) {
if (parse_generic_arg(argument, false)) {
continue;
}
new_argument_list.add(argument);
}
// now the first argument is: the action:
if (new_argument_list.size() == 0) {
Log.warning("--------------------------------------");
Log.warning("Missing the action to do ...");
Log.warning("--------------------------------------");
usage();
}
String action_to_do = new_argument_list.get(0).getArg();
new_argument_list.remove(0);
if (!Actions.exist(action_to_do)) {
Log.warning("--------------------------------------");
Log.warning("Wrong action type : '" + action_to_do + "' availlable list: " + Actions.getListOfAction());
Log.warning("--------------------------------------");
usage();
}
// todo : Remove this
if (!action_to_do.equals("init") && !Files.exists(Env.get_island_path())) {
Log.error("Can not execute a island cmd if we have not initialize a config: '" + "." + Env.get_system_base_name() + "' in upper 6 parent path");
System.exit(-1);
}
argss = argss.subList(this.my_args.getLastParsed()+1, argss.size());
Actions.execute(action_to_do, argss);
}
*/
public static void main(final String[] args) throws ActionException {
MainConfig tmp = new MainConfig();
ArgumentManager parser = new ArgumentManager(args, tmp, true);

View File

@ -30,8 +30,8 @@ public class Manifest {
Log.verbose("Lutin is not init: config does not exist: '" + Env.get_island_path_config() + "'");
return false;
}
if (!Files.exists(Env.get_island_path_manifest())) {
Log.verbose("Lutin is not init: Manifest does not exist: '" + Env.get_island_path_manifest() + "'");
if (!Files.exists(Env.getIslandPathManifest())) {
Log.verbose("Lutin is not init: Manifest does not exist: '" + Env.getIslandPathManifest() + "'");
return false;
}
return true;

View File

@ -46,7 +46,7 @@ public class Checkout {
configuration.setBranch(branch);
configuration.store();
Path file_source_manifest = Env.get_island_path_manifest().resolve(configuration.getManifestName());
Path file_source_manifest = Env.getIslandPathManifest().resolve(configuration.getManifestName());
if (!Files.exists(file_source_manifest)) {
Log.critical("Missing manifest file { '" + file_source_manifest.toAbsolutePath() + "'");
}
@ -64,7 +64,7 @@ public class Checkout {
}
}
if (have_error == true) {
//return Env.ret_action_fail;
Log.error("Checkout have fail !!! ");
}
}

View File

@ -0,0 +1,85 @@
package org.atriasoft.island.actions;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.atriasoft.death.annotation.ArgAlias;
import org.atriasoft.death.annotation.ArgCommand;
import org.atriasoft.death.annotation.ArgDescription;
import org.atriasoft.death.annotation.ArgExecute;
import org.atriasoft.death.annotation.ArgName;
import org.atriasoft.death.annotation.ArgSample;
import org.atriasoft.island.Commands;
import org.atriasoft.island.Config;
import org.atriasoft.island.Env;
import org.atriasoft.island.Manifest;
import org.atriasoft.island.Tools;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.ActionException;
import org.atriasoft.island.model.ConfigManifest;
import org.atriasoft.island.model.ProjectConfig;
import org.eclipse.jgit.api.Git;
@ArgCommand("commit")
@ArgDescription("commit in all repository")
@ArgSample("commit -a --amend -m \"[DEV] your comment\"")
public class Commit {
@ArgName("message")
@ArgAlias('m')
@ArgDescription("commit message to set on all modify repository")
public String message = "---No commit message---";
@ArgName("amend")
@ArgDescription("Ammend data to the previous commit")
public boolean amend = false;
@ArgName("all")
@ArgAlias('a')
@ArgDescription("All file are added")
public boolean all = false;
@ArgExecute
public void execute() throws ActionException, Exception {
// check system is OK
Manifest.checkIsInit();
ConfigManifest configuration = Config.getUniqueConfig();
// load the manifest after pulling it (if possible)
Path file_source_manifest = Env.getIslandPathManifest().resolve(configuration.getManifestName());
if (!Files.exists(file_source_manifest)) {
Log.critical("Missing manifest file : '" + file_source_manifest + "'");
}
Manifest mani = new Manifest(file_source_manifest);
List<ProjectConfig> all_project = mani.get_all_configs();
Log.print("Commit of: " + all_project.size() + " projects");
int id_element = 0;
for (ProjectConfig elem : all_project) {
id_element++;
String base_display = Tools.get_list_base_display(id_element, all_project.size(), elem);
Log.info("commit : " + base_display);
Path git_repo_path = Env.get_island_root_path().resolve(elem.getPath());
if ( !Commands.isGitRepository(git_repo_path.toString())) {
continue;
}
Git git = Git.open(git_repo_path.toFile());
boolean is_modify = git.status().call().hasUncommittedChanges();
if (!is_modify) {
Log.info("Not modify skip !! ");
continue;
}
// simply update the repository ...
git.commit()
.setAll(this.all)
.setAmend(this.amend)
.setMessage(this.message)
.call();
Log.print("[" + elem.getName() + "] commit done");
}
}
}

View File

@ -0,0 +1,89 @@
package org.atriasoft.island.actions;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.atriasoft.death.annotation.ArgAlias;
import org.atriasoft.death.annotation.ArgCommand;
import org.atriasoft.death.annotation.ArgDescription;
import org.atriasoft.death.annotation.ArgExecute;
import org.atriasoft.death.annotation.ArgName;
import org.atriasoft.death.annotation.ArgSample;
import org.atriasoft.island.Commands;
import org.atriasoft.island.Config;
import org.atriasoft.island.Env;
import org.atriasoft.island.Manifest;
import org.atriasoft.island.Tools;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.ActionException;
import org.atriasoft.island.model.ConfigManifest;
import org.atriasoft.island.model.ProjectConfig;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.TextProgressMonitor;
@ArgCommand("push")
@ArgDescription("Update all the repository remote branch")
@ArgSample("fetch --remote=github")
public class Fetch {
@ArgName("remote")
@ArgAlias('r')
@ArgDescription("Name of the remote server")
public String remote = "origin";
@ArgExecute
public void execute() throws ActionException, Exception {
// check system is OK
Manifest.checkIsInit();
ConfigManifest configuration = Config.getUniqueConfig();
// fetch or pull the manifest in case...
{
Git git = Git.open(Env.getIslandPathManifest().toFile());
git.fetch().setRemote(this.remote).call();
}
// load the manifest after pulling it (if possible)
Path file_source_manifest = Env.getIslandPathManifest().resolve(configuration.getManifestName());
if (!Files.exists(file_source_manifest)) {
Log.critical("Missing manifest file : '" + file_source_manifest + "'");
}
Manifest mani = new Manifest(file_source_manifest);
List<ProjectConfig> all_project = mani.get_all_configs();
Log.info("Synchronize of: " + all_project.size() + " projects");
int id_element = 0;
for (ProjectConfig elem : all_project) {
id_element++;
String base_display = Tools.get_list_base_display(id_element, all_project.size(), elem);
Log.print("fetch : " + base_display);
Tools.waitForServerIfNeeded();
Log.debug("elem : " + elem);
Path git_repo_path = Env.get_island_root_path().resolve(elem.getPath());
if (elem.getTag() != null) {
Log.todo("Need to select a specific tag version ... " + elem.getTag());
}
if (!Commands.isGitRepository(elem.getPath())) {
continue;
}
// simply update the repository ...
Log.verbose("Fetching project: ");
{
Git git = Git.open(git_repo_path.toFile());
git.fetch()
.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
.setRemote(elem.getSelectRemotes().getName())
.call();
Log.info("[" + elem.getName() + "] fetch done");
}
}
// Update the links:
//TODO: have_error = update_links.update(configuration, mani, "sync-local")
}
}

View File

@ -55,7 +55,7 @@ public class Init {
configuration.setManifestName(this.manifestFile);
configuration.store();
Tools.createDirectory(Env.get_island_path_manifest());
Tools.createDirectory(Env.getIslandPathManifest());
Log.info("Clone the manifest");
// init session on apache ssh:
SshdSessionFactory factory = new SshdSessionFactory(new JGitKeyCache(), new DefaultProxyDataFactory());
@ -65,58 +65,9 @@ public class Init {
Git git = Git.cloneRepository()
.setURI( addressManifest )
.setDirectory( Env.get_island_path_manifest().toFile() )
.setDirectory( Env.getIslandPathManifest().toFile() )
.setBranch(this.branch)
.call();
// TODO check all is good ==> return ...
/*
if ret_values == false:
Log.info("'" + str(ret_values) + "'")
Log.error("Init does not work")
return false
Log.info("Init done correctly ...")
return None
*/
// Path file_source_manifest = Env.get_island_path_manifest().resolve(configuration.getManifestName());
// if (!Files.exists(file_source_manifest)) {
// Log.critical("Missing manifest file : '" + file_source_manifest + "'");
// }
// Manifest mani = new Manifest(file_source_manifest);
// Log.error("Manifest loaded: config Len=" + mani.get_all_configs().size());
// /*
// Git git = Git.open(Env.get_island_path_manifest().toFile());
// boolean is_modify_manifest = git.status().call().hasUncommittedChanges();
// if (is_modify_manifest) {
// Log.info("!!!!!!!!!!!! MANIFEST is modify !!!!!!!!");
// }
// */
// List<ProjectConfig> all_project = mani.get_all_configs();
// Log.info("status of: " + all_project.size() + " projects");
// int id_element = 0;
//
// boolean is_behind = false;
// for (ProjectConfig elem : all_project) {
// id_element++;
// String base_display = Tools.get_list_base_display(id_element, all_project.size(), elem);
// Log.error(" base display: " + base_display);
// /*
// int ret = Status.displayStatus(elem, argument_remote_name, argument_display_tag, id_element, base_display);
// if (ret != 0) {
// is_behind = true;
// }
// */
// }
// if (is_behind == true) {
// //return Env.ret_action_need_updtate;
// }
}
}

View File

@ -0,0 +1,90 @@
package org.atriasoft.island.actions;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.util.List;
import org.atriasoft.death.annotation.ArgAlias;
import org.atriasoft.death.annotation.ArgCommand;
import org.atriasoft.death.annotation.ArgDescription;
import org.atriasoft.death.annotation.ArgExecute;
import org.atriasoft.death.annotation.ArgName;
import org.atriasoft.death.annotation.ArgSample;
import org.atriasoft.island.Commands;
import org.atriasoft.island.Config;
import org.atriasoft.island.Env;
import org.atriasoft.island.Manifest;
import org.atriasoft.island.Tools;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.ActionException;
import org.atriasoft.island.model.ConfigManifest;
import org.atriasoft.island.model.ProjectConfig;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.transport.PushResult;
@ArgCommand("push")
@ArgDescription("Push all repository to the upper server")
@ArgSample("push --remote=github")
public class Push {
@ArgName("remote")
@ArgAlias('r')
@ArgDescription("Name of the remote server")
public String remote = "origin";
@ArgName("force")
@ArgAlias('f')
@ArgDescription("Force the push on the remote")
public boolean force = false;
@ArgName("dry-run")
@ArgDescription("simulate all actions")
public boolean dryRun = false;
@ArgExecute
public void execute() throws ActionException, Exception {
String dryRunComment = this.dryRun ? " (DRY-RUN)" : "";
// check system is OK
Manifest.checkIsInit();
ConfigManifest configuration = Config.getUniqueConfig();
// load the manifest after pulling it (if possible)
Path file_source_manifest = Env.getIslandPathManifest().resolve(configuration.getManifestName());
Manifest mani = new Manifest(file_source_manifest);
List<ProjectConfig> all_project = mani.get_all_configs();
Log.info("Synchronize of: " + all_project.size() + " projects");
int id_element = 0;
for (ProjectConfig elem : all_project) {
id_element++;
String base_display = Tools.get_list_base_display(id_element, all_project.size(), elem);
Log.print("push : " + base_display + dryRunComment);
Tools.waitForServerIfNeeded();
Log.debug("elem : " + elem);
Path git_repo_path = Env.get_island_root_path().resolve(elem.getPath());
if (!Commands.isGitRepository(elem.getPath())) {
continue;
}
// simply update the repository ...
Log.verbose("push project: ");
{
Git git = Git.open(git_repo_path.toFile());
String select_branch = git.getRepository().getBranch();
Iterable<PushResult> plo = git.push()
.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
.setRemote(elem.getSelectRemotes().getName())
.setForce(this.force)
.add(select_branch)
.setDryRun(this.dryRun)
.call();
Log.info("[" + elem.getName() + "] fetch done " + dryRunComment);
}
}
// Update the links:
//TODO: have_error = update_links.update(configuration, mani, "sync-local")
}
}

View File

@ -29,7 +29,7 @@ public class Status {
@ArgName("remote")
@ArgAlias('r')
@ArgDescription("Name of the remote server")
public String remote = null;
public String remote = "origin";
@ArgName("tags")
@ArgAlias('t')
@ -42,12 +42,12 @@ public class Status {
Manifest.checkIsInit();
ConfigManifest configuration = Config.getUniqueConfig();
Path file_source_manifest = Env.get_island_path_manifest().resolve(configuration.getManifestName());
Path file_source_manifest = Env.getIslandPathManifest().resolve(configuration.getManifestName());
if (!Files.exists(file_source_manifest)) {
Log.critical("Missing manifest file : '" + file_source_manifest + "'");
}
Manifest mani = new Manifest(file_source_manifest);
Git git = Git.open(Env.get_island_path_manifest().toFile());
Git git = Git.open(Env.getIslandPathManifest().toFile());
boolean is_modify_manifest = git.status().call().hasUncommittedChanges();
if (is_modify_manifest) {
Log.info("!!!!!!!!!!!! MANIFEST is modify !!!!!!!!");

View File

@ -8,11 +8,12 @@ import java.util.List;
import org.atriasoft.island.Commands;
import org.atriasoft.island.Env;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.DeltaBranch;
import org.atriasoft.island.model.ProjectConfig;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
public class StatusActions {
@ -34,7 +35,7 @@ public class StatusActions {
Log.warning("checkout " + base_display + " ==> modify data can not checkout new branch");
return false;
}
List<String> list_branch_local = Commands.get_list_branch_local(git);
List<String> list_branch_local = Commands.getListBranchLocal(git);
String select_branch = git.getRepository().getBranch();
boolean is_tag = false;
@ -57,14 +58,14 @@ public class StatusActions {
}
// check if we have already checkout the branch before
Log.verbose(" check : " + branch_to_checkout + " in " + list_branch_local);
if (list_branch_local.contains(branch_to_checkout)) {
git.checkout().setCreateBranch(false).setName(branch_to_checkout).call();
if (list_branch_local.contains("refs/heads/" + branch_to_checkout)) {
git.checkout().setCreateBranch(false).setName("refs/heads/" + branch_to_checkout).call();
Log.info("checkout " + base_display + " ==> switch branch");
return true;
}
List<String> list_tags = Commands.get_tags(git);
if (list_tags.contains(branch_to_checkout)) {
List<String> list_tags = Commands.getTags(git);
if (list_tags.contains("refs/tags/" + branch_to_checkout)) {
is_tag = true;
if (elem.getTag() == null) {
elem.setTag(branch_to_checkout);
@ -76,12 +77,17 @@ public class StatusActions {
Log.info("checkout " + base_display + " ==> NO remote branch");
return true;
}
List<String> list_branch_remote = Commands.get_list_branch_remote(git);
List<String> list_branch_remote = Commands.getListBranchRemote(git);
String tryRemoteBranch = elem.getSelectRemotes().getName() + "/" + branch_to_checkout;
if (list_branch_remote.contains(tryRemoteBranch)) {
if (list_branch_remote.contains("refs/remotes/" + tryRemoteBranch)) {
Log.info(" ==> find ...");
try {
git.checkout().setCreateBranch(true).setName(tryRemoteBranch).call();
git.checkout()
.setCreateBranch(true)
.setName(branch_to_checkout)
.setUpstreamMode(SetupUpstreamMode.TRACK)
.setStartPoint(tryRemoteBranch)
.call();
} catch (Exception ex) {
ex.printStackTrace();
Log.error("checkout " + base_display + " ==> Can not checkout to the correct branch");
@ -129,15 +135,19 @@ public class StatusActions {
Git git = Git.open(git_repo_path.toFile());
boolean is_modify = git.status().call().hasUncommittedChanges();
List<String> list_branch = Commands.get_list_branch_all(git);
List<String> list_branch = Commands.getListBranchAll(git);
String select_branch = git.getRepository().getBranch();
Log.verbose("List all branch: " + list_branch);
String tracking_remote_branch = null;
if (!select_branch.startsWith(StatusActions.base_name_of_a_tagged_branch)) {
// get tracking branch
tracking_remote_branch = Commands.get_tracking_branch(git, argument_remote_name, select_branch);
tracking_remote_branch = Commands.getTrackingBranch(git, argument_remote_name, select_branch);
if (tracking_remote_branch == null) {
if (select_branch == null) {
Log.print(base_display + volatileString + "\r\t\t\t\t\t\t\t (NO BRANCH)");
} else {
Log.print(base_display + volatileString + "\r\t\t\t\t\t\t\t " + select_branch);
}
return 0;
}
} else {
@ -148,31 +158,16 @@ public class StatusActions {
modify_status = " *** ";
}
Log.verbose("select branch = '" + select_branch + "' is modify : " + is_modify + " track: '" + tracking_remote_branch + "'");
List<ObjectId> ret_current_branch_sha1 = Commands.get_revision_list_to_branch(git, select_branch);
List<ObjectId> ret_track_branch_sha1 = Commands.get_revision_list_to_branch(git, tracking_remote_branch);
// remove all identical sha1 ==> not needed for this
int in_forward = 0;
for (ObjectId elem_sha1 : ret_current_branch_sha1) {
if (!ret_track_branch_sha1.contains(elem_sha1)) {
in_forward++;
}
}
int in_behind = 0;
for (ObjectId elem_sha1 : ret_track_branch_sha1) {
if (!ret_current_branch_sha1.contains(elem_sha1)) {
in_behind++;
}
}
DeltaBranch deltas = Commands.getDeltaBranch(git, select_branch, tracking_remote_branch);
String behind_forward_comment = "";
if (in_forward != 0) {
behind_forward_comment += "forward=" + in_forward;
if (deltas.forward() != 0) {
behind_forward_comment += "forward=" + deltas.forward();
}
if (in_behind != 0) {
if (in_forward != 0) {
if (deltas.behind() != 0) {
if (deltas.forward() != 0) {
behind_forward_comment += " ";
}
behind_forward_comment += "behind=" + in_behind;
behind_forward_comment += "behind=" + deltas.behind();
}
if (behind_forward_comment != "") {
behind_forward_comment = "\r\t\t\t\t\t\t\t\t\t\t\t\t[" + behind_forward_comment + "]";
@ -181,7 +176,7 @@ public class StatusActions {
String tags_comment = "";
// check the current tags of the repository
if (argument_display_tag) {
List<String> ret_current_tags = Commands.get_tags_current(git);
List<String> ret_current_tags = Commands.getTagsCurrent(git);
Log.verbose("tags found: " + ret_current_tags);
for (String elem_tag : ret_current_tags) {
if (!tags_comment.isEmpty()) {
@ -196,10 +191,8 @@ public class StatusActions {
}
}
Log.print(base_display + volatileString + "\r\t\t\t\t\t\t\t" + modify_status + "(" + select_branch + " -> " + tracking_remote_branch + ")" + behind_forward_comment + tags_comment);
if (is_modify) {
Commands.get_diff(git);
}
return in_behind;
Commands.getDiff(git);
return deltas.behind();
}

View File

@ -51,7 +51,7 @@ public class Sync {
// fetch or pull the manifest in case...
{
Git git = Git.open(Env.get_island_path_manifest().toFile());
Git git = Git.open(Env.getIslandPathManifest().toFile());
boolean is_modify_manifest = git.status().call().hasUncommittedChanges();
if (is_modify_manifest) {
git.fetch().setRemote(this.remote).call();
@ -60,7 +60,7 @@ public class Sync {
}
}
// load the manifest after pulling it (if possible)
Path file_source_manifest = Env.get_island_path_manifest().resolve(configuration.getManifestName());
Path file_source_manifest = Env.getIslandPathManifest().resolve(configuration.getManifestName());
if (!Files.exists(file_source_manifest)) {
Log.critical("Missing manifest file : '" + file_source_manifest + "'");
}
@ -125,7 +125,7 @@ public class Sync {
// simply update the repository ...
Log.verbose("Fetching project: ");
{
Git git = Git.open(Env.get_island_path_manifest().toFile());
Git git = Git.open(git_repo_path.toFile());
Repository repo = git.getRepository();
// get tracking branch
String ret_track = new BranchConfig(repo.getConfig(), repo.getBranch()).getTrackingBranch();

View File

@ -0,0 +1,45 @@
package org.atriasoft.island.actions;
import org.atriasoft.death.annotation.ArgCommand;
import org.atriasoft.death.annotation.ArgDescription;
import org.atriasoft.death.annotation.ArgExecute;
import org.atriasoft.death.annotation.ArgParams;
import org.atriasoft.death.annotation.ArgParamsDescription;
import org.atriasoft.death.annotation.ArgSample;
import org.atriasoft.island.Config;
import org.atriasoft.island.Manifest;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.ActionException;
import org.atriasoft.island.model.ConfigManifest;
@ArgCommand("volatile-add")
@ArgDescription("Add a 'volatile' repository with a local path (this element is update as an element in the manifest but is not managed by the manifest)")
@ArgSample("volatile-add https://git.heeroyui.org/atria-tools/island.git git")
public class VolatileAdd {
@ArgExecute
@ArgParams({"git repository", "path"})
@ArgParamsDescription({"Git repositoty to download", "Path to install the new git repository"})
public void execute(final String remoteUrl, final String localPath) throws ActionException, Exception {
if (remoteUrl.isEmpty()) {
Log.error("volatile-add: Missing git repository address ...");
return;
}
Log.info("Add 'volatile' repository: '" + remoteUrl + "' path='" + localPath + "'");
// check system is OK
Manifest.checkIsInit();
// Update the current configuration:
ConfigManifest configuration = Config.getUniqueConfig();
if (configuration.existVolatile(localPath)) {
Log.error("Volatile Already exist !!!");
return;
}
// TODO: Check if the local path does not exist in the manifest
configuration.addVolatile(remoteUrl, localPath);
configuration.store();
Log.print("Volatile added: " + localPath);
}
}

View File

@ -0,0 +1,41 @@
package org.atriasoft.island.actions;
import java.util.List;
import org.atriasoft.death.annotation.ArgCommand;
import org.atriasoft.death.annotation.ArgDescription;
import org.atriasoft.death.annotation.ArgExecute;
import org.atriasoft.death.annotation.ArgSample;
import org.atriasoft.island.Config;
import org.atriasoft.island.Manifest;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.ActionException;
import org.atriasoft.island.model.ConfigManifest;
import org.atriasoft.island.model.Volatile;
@ArgCommand("volatile-list")
@ArgDescription("List all volatiles elements")
@ArgSample("volatile-list")
public class VolatileList {
@ArgExecute
public void execute() throws ActionException, Exception {
Log.info("List all 'volatile'");
// check system is OK
Manifest.checkIsInit();
// Update the current configuration:
ConfigManifest configuration = Config.getUniqueConfig();
List<Volatile> volatiles = configuration.getVolatiles();
Log.print("List of volatiles:");
if (volatiles.size() == 0) {
Log.print("\t==> No repository");
} else {
for (Volatile elem : volatiles) {
Log.print("\t" + elem.getPath() + "\r\t\t\t\t" + elem.getGitAddress());
}
}
}
}

View File

@ -0,0 +1,40 @@
package org.atriasoft.island.actions;
import org.atriasoft.death.annotation.ArgCommand;
import org.atriasoft.death.annotation.ArgDescription;
import org.atriasoft.death.annotation.ArgExecute;
import org.atriasoft.death.annotation.ArgParams;
import org.atriasoft.death.annotation.ArgParamsDescription;
import org.atriasoft.death.annotation.ArgSample;
import org.atriasoft.island.Config;
import org.atriasoft.island.Manifest;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.ActionException;
import org.atriasoft.island.model.ConfigManifest;
@ArgCommand("volatile-rm")
@ArgDescription("Remove a 'volatile' repository with a local path")
@ArgSample("volatile-rm git")
public class VolatileRemove {
@ArgExecute
@ArgParams("path")
@ArgParamsDescription("Path to install the new git repository")
public void execute(final String localPath) throws ActionException, Exception {
Log.info("Remove 'volatile' repository: path='" + localPath + "'");
// check system is OK
Manifest.checkIsInit();
// Update the current configuration:
ConfigManifest configuration = Config.getUniqueConfig();
if (!configuration.existVolatile(localPath)) {
Log.error("Volatile Does not exist !!!");
return;
}
// TODO: Check if the local path does not exist in the manifest
configuration.rmVolatile(localPath);
configuration.store();
Log.print("Volatile Removed: " + localPath);
}
}

View File

@ -49,7 +49,7 @@ public class Log {
public static void print(final String data) {
if (Log.PRINT_PRINT || Log.FORCE) {
Logger.print(Log.LIB_NAME_DRAW, data);
System.out.println(data);
}
}

View File

@ -54,15 +54,25 @@ public class ConfigManifest {
rmVolatile(path);
this.volatiles.add(new Volatile(gitAddress, path));
}
private void rmVolatile(final String path) {
public void rmVolatile(final String path) {
ListIterator<Volatile> it = this.volatiles.listIterator();
while (it.hasNext()) {
Volatile elem = it.next();
if (elem.path.equals(path)) {
if (elem.getPath().equals(path)) {
it.remove();
}
}
}
public boolean existVolatile(final String path) {
ListIterator<Volatile> it = this.volatiles.listIterator();
while (it.hasNext()) {
Volatile elem = it.next();
if (elem.getPath().equals(path)) {
return true;
}
}
return false;
}
@XmlList(value="link")
public List<Link> getLinks() {
return this.links;

View File

@ -0,0 +1,5 @@
package org.atriasoft.island.model;
public record DeltaBranch(int forward, int behind) {
}

View File

@ -1,10 +1,31 @@
package org.atriasoft.island.model;
import org.atriasoft.exml.annotation.XmlDefaultAttibute;
import org.atriasoft.exml.annotation.XmlName;
@XmlDefaultAttibute
public class Volatile {
public String gitAddress;
public String path;
private String gitAddress;
private String path;
@XmlName({"address", "path"})
public Volatile(final String gitAddress, final String path) {
this.gitAddress = gitAddress;
this.path = path;
}
@XmlName("address")
public String getGitAddress() {
return this.gitAddress;
}
public void setGitAddress(final String gitAddress) {
this.gitAddress = gitAddress;
}
@XmlName("path")
public String getPath() {
return this.path;
}
public void setPath(final String path) {
this.path = path;
}
}

View File

@ -1,95 +0,0 @@
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
from realog import Log
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import os
//#
//# @brief Get the global description of the current action
//# @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
//#
public void help():
return "Commit in all repository"
//#
//# @brief Add argument to the specific action
//# @param[in,out] my_args (death.Arguments) Argument manager
//# @param[in] section Name of the currect action
//#
public void add_specific_arguments(my_args, section):
my_args.add("m", "message", haveParam=true, desc="Message to commit data")
my_args.add("a", "all", desc="Commit all elements")
my_args.add("", "amend", desc="Ammend data at the previous commit")
//#
//# @brief Execute the action required.
//#
//# @return error value [0 .. 50] the <0 value is reserved system ==> else, what you want.
//# None : No error (return program out 0)
//# -10 : ACTION is not existing
//# -11 : ACTION execution system error
//# -12 : ACTION Wrong parameters
//#
public void execute(_arguments):
argument_message = ""
argument_amend = ""
argument_all = ""
for elem in _arguments:
if elem.getOptionName().equals("message":
Log.info("find message: '" + elem.getArg() + "'")
argument_message = " --message \"" + elem.getArg() + "\" ";
} else if elem.getOptionName().equals("all":
argument_all = " --all "
} else if elem.getOptionName().equals("amend":
argument_amend = " --amend "
else:
Log.error("Wrong argument: '" + elem.getOptionName() + "' '" + elem.getArg() + "'")
// check system is OK
Manifest.checkIsInit();
ConfigManifest configuration = Config.getUniqueConfig();
file_source_manifest = new Path(Env.get_island_path_manifest(), configuration.get_manifest_name())
if os.path.exists(file_source_manifest) == false:
Log.error("Missing manifest file : '" + str(file_source_manifest) + "'")
mani = manifest.Manifest(file_source_manifest)
all_project = mani.get_all_configs()
Log.info("commit : " + str(len(all_project)) + " projects")
id_element = 0
for elem in all_project:
id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
Log.info("commit: " + base_display)
git_repo_path = new Path(Env.get_island_root_path(), elem.path)
if os.path.exists(git_repo_path) == false:
Log.error("can not commit project that not exist")
continue
if os.path.exists(new Path(git_repo_path,".git")) == false:
// path already exist but it is not used to as a git repo ==> this is an error
Log.warning("path '" + git_repo_path + "' is already existing but not used for a git repository. Clean it and restart")
continue;
// simply update the repository ...
Log.verbose("commit in project:")
// fetch the repository
cmd = "git commit " + argument_amend + argument_all + argument_message
Log.debug("execute : " + cmd)
multiprocess.run_command_direct(cmd, cwd=git_repo_path)

View File

@ -1,92 +0,0 @@
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
from realog import Log
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import os
//#
//# @brief Get the global description of the current action
//# @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
//#
public void help():
return "Fecth all the repository (get all modification on the server)"
//#
//# @brief Add argument to the specific action
//# @param[in,out] my_args (death.Arguments) Argument manager
//# @param[in] section Name of the currect action
//#
public void add_specific_arguments(my_args, section):
my_args.add("r", "remote", haveParam=true, desc="Name of the remote server")
//#
//# @brief Execute the action required.
//#
//# @return error value [0 .. 50] the <0 value is reserved system ==> else, what you want.
//# None : No error (return program out 0)
//# -10 : ACTION is not existing
//# -11 : ACTION execution system error
//# -12 : ACTION Wrong parameters
//#
public void execute(_arguments):
argument_remote_name = ""
for elem in _arguments:
if elem.getOptionName().equals("remote":
Log.info("find remote name: '" + elem.getArg() + "'")
argument_remote_name = elem.getArg()
else:
Log.error("Wrong argument: '" + elem.getOptionName() + "' '" + elem.getArg() + "'")
// check system is OK
Manifest.checkIsInit();
Log.info("fetch manifest : '" + str(Env.get_island_path_manifest()) + "'")
commands.fetch(Env.get_island_path_manifest(), "origin")
ConfigManifest configuration = Config.getUniqueConfig();
file_source_manifest = new Path(Env.get_island_path_manifest(), configuration.get_manifest_name())
if os.path.exists(file_source_manifest) == false:
Log.error("Missing manifest file : '" + str(file_source_manifest) + "'")
mani = manifest.Manifest(file_source_manifest)
all_project = mani.get_all_configs()
Log.info("fetch : " + str(len(all_project)) + " projects")
id_element = 0
for elem in all_project:
id_element += 1
// configure remote name:
if argument_remote_name.equals("":
argument_remote_name = elem.select_remote["name"]
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
Log.info("fetch: " + base_display)
tools.wait_for_server_if_needed()
//Log.debug("elem : " + str(elem))
git_repo_path = new Path(Env.get_island_root_path(), elem.path)
if os.path.exists(git_repo_path) == false:
Log.error("can not fetch project that not exist")
continue
if os.path.exists(new Path(git_repo_path,".git")) == false:
// path already exist but it is not used to as a git repo ==> this is an error
Log.error("path '" + git_repo_path + "' is already existing but not used for a git repository. Clean it and restart")
// simply update the repository ...
Log.verbose("Fetching project: ")
commands.fetch(git_repo_path, argument_remote_name)

View File

@ -1,114 +0,0 @@
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
from realog import Log
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import os
//#
//# @brief Get the global description of the current action
//# @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
//#
public void help():
return "Push all repository to the upper server"
//#
//# @brief Add argument to the specific action
//# @param[in,out] my_args (death.Arguments) Argument manager
//# @param[in] section Name of the currect action
//#
public void add_specific_arguments(_my_args, _section):
_my_args.add("r", "remote", haveParam=true, desc="Name of the remote server")
//#
//# @brief Execute the action required.
//#
//# @return error value [0 .. 50] the <0 value is reserved system ==> else, what you want.
//# None : No error (return program out 0)
//# -10 : ACTION is not existing
//# -11 : ACTION execution system error
//# -12 : ACTION Wrong parameters
//#
public void execute(_arguments):
argument_remote_name = ""
for elem in _arguments:
if elem.getOptionName().equals("remote":
Log.info("find remote name: '" + elem.getArg() + "'")
argument_remote_name = elem.getArg()
else:
Log.error("Wrong argument: '" + elem.getOptionName() + "' '" + elem.getArg() + "'")
// check system is OK
Manifest.checkIsInit();
ConfigManifest configuration = Config.getUniqueConfig();
file_source_manifest = new Path(Env.get_island_path_manifest(), configuration.get_manifest_name())
if os.path.exists(file_source_manifest) == false:
Log.error("Missing manifest file : '" + str(file_source_manifest) + "'")
mani = manifest.Manifest(file_source_manifest)
all_project = mani.get_all_configs()
Log.info("fetch : " + str(len(all_project)) + " projects")
id_element = 0
for elem in all_project:
id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
Log.info("push: " + base_display)
tools.wait_for_server_if_needed()
//Log.debug("elem : " + str(elem))
git_repo_path = new Path(Env.get_island_root_path(), elem.path)
if os.path.exists(git_repo_path) == false:
Log.error("can not push project that not exist")
continue
if os.path.exists(new Path(git_repo_path,".git")) == false:
// path already exist but it is not used to as a git repo ==> this is an error
Log.error("path '" + git_repo_path + "' exist but not used for a git repository. Clean it and restart")
// get the current branch:
// get local branch
cmd = "git branch -a"
Log.verbose("execute : " + cmd)
ret_branch = multiprocess.run_command(cmd, cwd=git_repo_path)
list_branch = ret_branch[1].split('\n')
list_branch2 = []
list_branch3 = []
select_branch = ""
for elem_branch in list_branch:
if len(elem_branch.split(" -> ")) != 1:
continue
if elem_branch[2:10].equals("remotes/":
elem_branch = elem_branch[:2] + elem_branch[10:]
if elem_branch[:2].equals("* ":
list_branch2.append([elem_branch[2:], true])
select_branch = elem_branch[2:]
else:
list_branch2.append([elem_branch[2:], false])
list_branch3.append(elem_branch[2:])
// simply update the repository ...
Log.verbose("Push project: ")
// fetch the repository
cmd = "git push"
if argument_remote_name != "":
cmd += " " + argument_remote_name
else:
cmd += " " + elem.select_remote["name"]
cmd += " " + select_branch + ":" + select_branch
Log.info("execute : " + cmd)
multiprocess.run_command_direct(cmd, cwd=git_repo_path)

View File

@ -1,86 +0,0 @@
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
from realog import Log
from island import tools
from island import env
from island import config
from island import commands
from island import multiprocess
from island import manifest
import os
//#
//# @brief Get the global description of the current action
//# @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
//#
public void help():
return "Add a 'volatile' repository with a local path (this element is update as an element in the manifest but is not managed by the manifest)"
//#
//# @brief Add argument to the specific action
//# @param[in,out] my_args (death.Arguments) Argument manager
//# @param[in] section Name of the currect action
//#
public void add_specific_arguments(my_args, section):
my_args.add_arg("git repository", optionnal=false, desc="Git repositoty to download")
my_args.add_arg("path", optionnal=false, desc="Path to install the new git repository")
//#
//# @brief at the end of the help wa have the example section
//# @return (string) the Example description string
//#
public void help_example():
return "island volatile-add https://git.heeroyui.org/atria-tools/island.git git"
//#
//# @brief Execute the action required.
//#
//# @return error value [0 .. 50] the <0 value is reserved system ==> else, what you want.
//# None : No error (return program out 0)
//# -5 : Env.ret_manifest_is_not_existing : Manifest does not exit
//# -10 : Env.ret_action_is_not_existing : ACTION is not existing
//# -11 : Env.ret_action_executing_system_error : ACTION execution system error
//# -12 : Env.ret_action_wrong_parameters : ACTION Wrong parameters
//# -13 : Env.ret_action_partial_done : ACTION partially done
//#
public void execute(_arguments):
if len(_arguments) == 0:
Log.error("Missing argument to execute the current action [git repository] [path]")
// the configuration availlable:
path = ""
address_git = ""
for elem in _arguments:
if elem.getOptionName().equals("git repository":
address_git = elem.getArg()
} else if elem.getOptionName().equals("path":
path = elem.getArg()
else:
Log.error("Wrong argument: '" + elem.getOptionName() + "' '" + elem.getArg() + "'")
if address_git.equals("":
Log.error("volatile-add: Missing git repository address", Env.ret_action_wrong_parameters)
Log.info("Add 'volatile' repository: '" + address_git + "' path='" + path + "'")
// check system is OK
Manifest.checkIsInit();
// Update the current configuration:
conf = config.get_unique_config()
// TODO: Check if the local path does not exist in the manifest
if false == conf.add_volatile(address_git, path):
return Env.ret_action_executing_system_error
conf.store()
return None

View File

@ -1,53 +0,0 @@
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
from realog import Log
from island import tools
from island import env
from island import config
from island import commands
from island import multiprocess
from island import manifest
import os
//#
//# @brief Get the global description of the current action
//# @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
//#
public void help():
return "List all the volatil repository"
//#
//# @brief Execute the action required.
//#
//# @return error value [0 .. 50] the <0 value is reserved system ==> else, what you want.
//# None : No error (return program out 0)
//# -5 : Env.ret_manifest_is_not_existing : Manifest does not exit
//# -10 : Env.ret_action_is_not_existing : ACTION is not existing
//# -11 : Env.ret_action_executing_system_error : ACTION execution system error
//# -12 : Env.ret_action_wrong_parameters : ACTION Wrong parameters
//# -13 : Env.ret_action_partial_done : ACTION partially done
//#
public void execute(_arguments):
for elem in _arguments:
Log.error("Wrong argument: '" + elem.getOptionName() + "' '" + elem.getArg() + "'")
// check system is OK
Manifest.checkIsInit();
conf = config.get_unique_config()
volatiles = conf.get_volatile()
Log.info("List of all volatiles repository: ")
for elem in volatiles:
Log.info("\t" + elem["path"] + "\r\t\t\t\t" + elem["git_address"])
return None

View File

@ -1,329 +0,0 @@
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
import os
import shutil
import errno
import fnmatch
import stat
// Local import
from realog import Log
from . import env
from . import multiprocess
from . import Log
"""
"""
public void check_repository_is_modify(path_repository):
// check if the repository is modify
cmd = "git diff --quiet"
Log.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "check_repository_is_modify", error_only=true, availlable_return=[0,1], display_if_nothing=false)
ret_diff = return_value
if ret_diff[0] == 0:
return false
return true
public void get_list_branch_meta(path_repository):
// get local branch
cmd = "git branch -a"
Log.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "get_list_branch_meta", error_only=true)
ret_branch = return_value
list_branch = ret_branch[1].split('\n')
out = []
for elem_branch in list_branch:
is_remote = false
branch_name = ""
is_selected = false
if len(elem_branch.split(" -> ")) != 1:
continue
// separate the remote element
if elem_branch[2:10].equals("remotes/":
elem_branch = elem_branch[:2] + elem_branch[10:]
is_remote = true
// separate select branch
if elem_branch[:2].equals("* ":
is_selected = true
branch_name = elem_branch[2:]
else:
branch_name = elem_branch[2:]
out.append({
"remote": is_remote,
"name": branch_name,
"select": is_selected
})
Log.extreme_verbose("List all branch Meta: " + str(out))
return out
public void get_list_branch_all(path_repository):
tmp = get_list_branch_meta(path_repository)
out = []
for elem in tmp:
out.append(elem["name"])
Log.verbose("List all branch: " + str(out))
return out
public void get_current_branch(path_repository):
tmp = get_list_branch_meta(path_repository)
for elem in tmp:
if elem["select"] == true:
Log.verbose("List local branch: " + str(elem["name"]))
return elem["name"]
Log.verbose("List local branch: None" )
return None
public void get_specific_commit_message(path_repository, sha_1):
if sha_1 == None or sha_1.equals("":
return ""
cmd = "git log --format=%B -n 1 " + sha_1
Log.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "get_specific_commit_message", error_only=true)
return return_value[1].split('\n')[0]
public void get_sha1_for_branch(path_repository, branch_name):
if branch_name == None or branch_name.equals("":
return None
cmd = "git rev-parse " + branch_name
Log.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "get_sha1_for_branch", error_only=true)
return return_value[1].split('\n')[0]
public void get_tags_remote(path_repository, remote_name):
if remote_name.equals("" or remote_name == None:
return get_current_tracking_branch(path_repository)
cmd = "git ls-remote --tags " + remote_name
Log.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "get_tags_remote", error_only=true)
list_element = return_value[1].split('\n')
Log.verbose(" receive: " + str(list_element))
//6bc01117e85d00686ae2d423193a161e82df9a44 refs/tags/0.1.0
//7ef9caa51cf3744de0f46352e5aa07bd4980fe89 refs/tags/v0.2.0
//870e8e039b0a98370a9d23844f0af66824c57a5f refs/tags/v0.2.0^{}
//16707e17e58f16b3409f8c64df7f595ba7dcf499 refs/tags/v0.3.0
//dfb97c3dfea776e5c4862dc9f60f8c5ad83b55eb refs/tags/v0.3.0^{}
out = []
for elem in list_element:
cut = elem.split("\t")
if len(cut) != 2:
continue
if cut[1][-3:].equals("^{}":
// specific usage for the annotated commit
continue
if cut[1][:10].equals("refs/tags/":
out.append(cut[1][10:])
else:
out.append(cut[1])
return out
public void merge_branch_on_master(path_repository, branch_name, merge_force=true, branch_destination = "master"):
if branch_name == None or branch_name.equals("":
raise "Missing branch name"
cmd = "git merge "
if merge_force == true:
cmd += "--no-ff "
cmd += branch_name + " --message \"Merge branch '" + branch_name + "' into '" + branch_destination + "'\""
Log.verbose("execute : " + cmd)
// TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "merge_branch_on_master", error_only=true)
return return_value
public void add_file(path_repository, file_path):
if file_path == None or file_path.equals("":
raise "Missing file_path name"
cmd = "git add " + file_path
Log.verbose("execute : " + cmd)
// TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "add_file", error_only=true)
return return_value
public void commit_all(path_repository, comment):
if comment == None or comment.equals("":
raise "Missing comment description"
cmd = 'git commit -a --message "' + comment +'"'
Log.verbose("execute : " + cmd)
// TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "commit_all", error_only=true)
return return_value
public void tag(path_repository, tag_name):
if tag_name == None or tag_name.equals("":
raise "Missing tag name"
tag_name = tag_name.replace(" ", "_")
cmd = 'git tag ' + tag_name + ' --message "[TAG] create tag ' + tag_name +'"'
Log.verbose("execute : " + cmd)
// TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "tag", error_only=true)
return return_value
public void checkout(path_repository, branch_name):
if branch_name == None or branch_name.equals("":
raise "Missing branch name"
cmd = 'git checkout ' + branch_name
Log.verbose("execute : " + cmd)
// TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "checkout", error_only=true)
return return_value
public void reset_hard(path_repository, destination):
if destination == None or destination.equals("":
raise "Missing destination 'sha1' or 'branch name'"
cmd = 'git reset --hard ' + destination
Log.verbose("execute : " + cmd)
// TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "reset_hard", error_only=true)
return return_value
public void rebase(path_repository, destination):
if destination == None or destination.equals("":
raise "Missing destination 'sha1' or 'branch name'"
cmd = 'git rebase ' + destination
Log.verbose("execute : " + cmd)
// TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "rebase", error_only=true)
return return_value
public void clone(path_repository, address, branch_name = None, origin=None):
if address == None or address.equals("":
raise "Missing address"
cmd = 'git clone ' + address
if branch_name != None and branch_name.equals("":
cmd += " --branch " + branch_name
if origin != None and origin.equals("":
cmd += " --origin " + origin
if path_repository != None and path_repository != "":
cmd += " " + path_repository
Log.verbose("execute : " + cmd)
if os.path.exists(path_repository) == true:
Log.warning("Can not clone repository path already exist")
return false
return_value = multiprocess.run_command(cmd)
multiprocess.generic_display_error(return_value, "clone", error_only=true)
return return_value
public void fetch(path_repository, remote_name, prune=true):
cmd = 'git fetch ' + remote_name
if prune == true:
cmd += " --prune"
Log.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "fetch")
return return_value
public void pull(path_repository, remote_name, prune=true):
if remote_name == None or remote_name.equals("":
raise "Missing remote_name"
cmd = 'git pull ' + remote_name
if prune == true:
cmd += " --prune"
Log.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "pull")
return return_value
public void push(path_repository, remote_name, elements):
if remote_name == None or remote_name.equals("":
raise "Missing remote_name"
if len(elements) == 0:
raise "No elements to push on server"
cmd = 'git push ' + remote_name
for elem in elements:
cmd += " " + elem
Log.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "push")
return return_value
public void submodule_sync(path_repository, remote_name):
cmd = "git submodule sync"
Log.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "submodule_sync")
"""
if ret[:31].equals("Synchronizing submodule url for":
//all is good ...
Log.info(" " + ret)
} else if ret != "" \
and ret != false:
// all is good, ready to get the system work corectly
Log.info("'" + ret + "'")
Log.error("Can not sync submodules ... ")
"""
public void get_forward(path_repository, branch_name):
if branch_name == None or branch_name.equals("":
raise "get_fast_forward: Missing branch_name"
select_branch = get_current_branch(path_repository)
// get tracking branch
ret_current_branch_sha1 = get_revision_list_to_branch(path_repository, select_branch)
ret_track_branch_sha1 = get_revision_list_to_branch(path_repository, branch_name)
// count the number of commit fast forward
forward_count = 0
for elem_sha1 in ret_current_branch_sha1:
if elem_sha1 not in ret_track_branch_sha1:
forward_count += 1
return forward_count
public void is_forward(path_repository, branch_name):
return get_forward(path_repository, branch_name) != 0;
public void get_behind(path_repository, branch_name):
if branch_name == None or branch_name.equals("":
raise "get_fast_forward: Missing branch_name"
select_branch = get_current_branch(path_repository)
// get tracking branch
ret_current_branch_sha1 = get_revision_list_to_branch(path_repository, select_branch)
ret_track_branch_sha1 = get_revision_list_to_branch(path_repository, branch_name)
// count the number of commit behind
behind_count = 0
for elem_sha1 in ret_track_branch_sha1:
if elem_sha1 not in ret_current_branch_sha1:
behind_count += 1
return behind_count
public void is_behind(path_repository, branch_name):
return get_behind(path_repository, branch_name) != 0;

View File

@ -1,26 +0,0 @@
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
import platform
import sys
// Local import
from realog import Log
// print os.name # ==> 'posix'
if platform.system().equals("Linux":
OS = "Linux"
} else if platform.system().equals("Windows":
OS = "Windows"
} else if platform.system().equals("Darwin":
OS = "MacOs"
else:
Log.error("Unknow the Host OS ... '" + platform.system() + "'")
Log.debug("host.OS = " + OS)

View File

@ -1,118 +0,0 @@
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
import sys
import threading
import time
import sys
import os
import subprocess
import shlex
// Local import
from realog import Log
from . import tools
from . import env
public void generic_display_error(return_value, type_name, error_only=false, availlable_return=[0], display_if_nothing=true):
Log.verbose(str(return_value))
if return_value[0] in availlable_return:
if error_only == true:
return
display = false
if return_value[1] != "":
Log.info(return_value[1])
display = true
if return_value[2] != "":
Log.warning(return_value[2])
display = true
if display_if_nothing == false:
return
if display == false:
Log.verbose("GIT(" + type_name + "): All done OK")
else:
display = false
if return_value[1] != "":
Log.warning("ERROR GIT(" + type_name + ") 1:" + return_value[1])
display = true
if return_value[2] != "":
Log.warning("ERROR GIT(" + type_name + ") 2:" + return_value[2])
display = true
if display == false:
Log.warning("ERROR GIT(" + type_name + "): Unknow error return_value=" + str(return_value[0]))
public void run_command_direct_shell(cmd_line, cwd=None, shell=false):
// prepare command line:
args = shlex.split(cmd_line)
Log.verbose("cmd = " + str(args))
subprocess.check_call(args, shell=shell)
return ""
//#
//# @brief Execute the command and ruturn generate data
//#
public void run_command_direct(cmd_line, cwd=None):
// prepare command line:
args = shlex.split(cmd_line)
Log.verbose("cmd = " + str(args))
"""
if true:
subprocess.check_call(args)
return ""
"""
try:
// create the subprocess
//p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
//p = subprocess.check_call(args)
"""
if cwd != None:
Log.info("path = " + cwd)
"""
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
except subprocess.CalledProcessError as e:
Log.error("subprocess.CalledProcessError : " + str(args))
except:
Log.error("Exception on : " + str(args))
// launch the subprocess:
output, err = p.communicate()
if sys.version_info >= (3, 0):
output = output.decode("utf-8")
err = err.decode("utf-8")
// Check errors:
if p.returncode == 0:
if output == None:
return err[:-1];
return output[:-1];
else:
return false
public void run_command(cmd_line, cwd=None):
// prepare command line:
args = shlex.split(cmd_line)
Log.verbose("cmd = " + str(args))
try:
// create the subprocess
"""
if cwd != None:
Log.info("path = " + cwd)
"""
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
except subprocess.CalledProcessError as e:
Log.error("subprocess.CalledProcessError : " + str(args))
except:
Log.error("Exception on : " + str(args))
// launch the subprocess:
output, err = p.communicate()
if sys.version_info >= (3, 0):
output = output.decode("utf-8")
err = err.decode("utf-8")
// Check error :
return [p.returncode, output[:-1], err[:-1]]

View File

@ -1,51 +0,0 @@
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
from realog import Log
from . import tools
from . import env
class RepoConfig():
public void __init__(self):
self.name = ""
self.path = ""
self.remotes = [] // list of all remotes, with the upstream elements (needed for third party integrations)
self.select_remote = ""
self.branch = ""
self.tag = None
self.volatile = false
public void split_repo(git_repo):
Log.verbose("parse git repo in RAW: " + str(git_repo))
if len(git_repo) > 4 \
and git_repo[:4].equals("http":
// http://wdfqsdfqs@qsdfqsdf/qsdfqsdf/qsdfqsdf/qsdfqs.git find the 3rd '/' and cut at this point
elements = git_repo.split('/')
if len(elements) < 4:
Log.error("Can not parse the git repository : '" + str(git_repo) + "' wrong format http?://xxx@xxx.xxx/****")
base = elements[0] + "/" + elements[1] + "/" + elements[2]
repo = git_repo[len(base)+1:]
} else if len(git_repo) > 3 \
and git_repo[:3].equals("git":
// git@qsdfqsdf:qsdfqsdf/qsdfqsdf/qsdfqs.git find the 1st ':' and cut at this point
elements = git_repo.split(':')
if len(elements) < 2:
Log.error("Can not parse the git repository : '" + str(git_repo) + "' wrong format git@xxx.xxx:****")
base = elements[0]
repo = git_repo[len(base)+1:]
else:
Log.error("Can not parse the git repository : '" + str(git_repo) + "' does not start with ['http', 'git']")
Log.verbose(" base: " + str(base))
Log.verbose(" repo: " + str(repo))
return (base, repo)