From d5bd432d59d67d75c1584fc9070b92f1c4af0586 Mon Sep 17 00:00:00 2001 From: Mathieu Benoit Date: Sat, 11 Jul 2020 21:13:44 -0400 Subject: [PATCH] [FIX] add git_diff_repo_manifest to show diff code between 2 manifests --- doc/DEVELOPMENT.md | 6 ++ doc/RELEASE.md | 8 ++- script/git_diff_repo_manifest.py | 95 ++++++++++++++++++++++++++++++++ script/git_tool.py | 22 +++++++- 4 files changed, 127 insertions(+), 4 deletions(-) create mode 100755 script/git_diff_repo_manifest.py diff --git a/doc/DEVELOPMENT.md b/doc/DEVELOPMENT.md index a0b36c7..b298926 100644 --- a/doc/DEVELOPMENT.md +++ b/doc/DEVELOPMENT.md @@ -84,6 +84,12 @@ Tools to synchronise the repo with another project. This will show differences a ./script/git_change_remote.py --sync_to /path/to/project/erplibre ``` +## Diff code between manifest +To show diff between commits in different manifest +```bash +./script/git_diff_repo_manifest.py --input1 ./manifest/MANIFEST1.xml --input2 ./manifest/MANIFEST2.xml +``` + ## Add repo Access to a new repo, add your URL to file [source_repo_addons.csv](../source_repo_addons.csv) diff --git a/doc/RELEASE.md b/doc/RELEASE.md index fe8acbe..e73a371 100644 --- a/doc/RELEASE.md +++ b/doc/RELEASE.md @@ -15,12 +15,18 @@ When ready to make a release, create a branch release/#.#.# and create a pull re Update file CHANGELOG.md and create a section with new version. Merge it when maintener accept it. -Add a tag on the commit on branch master with your release. +Add a tag on the commit on branch master with your release. When adding tag, be sure to update default.xml ```bash git tag v#.#.# # Push your tags git push --tags +# Add tags for all repo +./venv/repo forall -pc "git tag ERPLibre/v#.#.#" +./venv/repo forall -pc "git push ERPLibre --tags" +# Get all difference between a tag and HEAD, to update the CHANGELOG.md +./venv/repo forall -pc "git diff ERPLibre/v#.#.#..HEAD" ``` + # TIPS ## Compare diff repo with another ERPLibre project To generate a list of differences between repo git commit, do diff --git a/script/git_diff_repo_manifest.py b/script/git_diff_repo_manifest.py new file mode 100755 index 0000000..b969bd4 --- /dev/null +++ b/script/git_diff_repo_manifest.py @@ -0,0 +1,95 @@ +#!./venv/bin/python +import os +import sys +import argparse +import logging +from git import Repo + +new_path = os.path.normpath(os.path.join(os.path.dirname(__file__), '..')) +sys.path.append(new_path) + +from script.git_tool import GitTool + +_logger = logging.getLogger(__name__) + + +def get_config(): + """Parse command line arguments, extracting the config file name, + returning the union of config file and command line arguments + + :return: dict of config file settings and command line arguments + """ + # TODO update description + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description="""Get git diff between manifest repo revision, + diff revision input1 to input2 """, + epilog='''\ +''' + ) + parser.add_argument('--input1', required=True, + help="Compare input1 to input2. Input1 is older config.") + parser.add_argument('--input2', required=True, + help="Compare input1 to input2. Input2 is newer config.") + # parser.add_argument('--clear', action="store_true", + # help="Create a new manifest and clear old configuration.") + args = parser.parse_args() + return args + + +def main(): + config = get_config() + git_tool = GitTool() + + dct_remote_1, dct_project_1, default_remote_1 = git_tool.get_manifest_xml_info( + filename=config.input1, add_root=True) + dct_remote_2, dct_project_2, default_remote_2 = git_tool.get_manifest_xml_info( + filename=config.input2, add_root=True) + + set_project_1 = set(dct_project_1.keys()) + set_project_2 = set(dct_project_2.keys()) + lst_same_name_normalize = set_project_1.intersection(set_project_2) + lst_missing_name_normalize = set_project_2.difference(set_project_1) + lst_over_name_normalize = set_project_1.difference(set_project_2) + + i = 0 + total = len(lst_same_name_normalize) + for key in lst_missing_name_normalize: + i += 1 + print(f"{i}/{total} - {key} from input1 not in input2.") + + i = 0 + total = len(lst_over_name_normalize) + for key in lst_over_name_normalize: + i += 1 + print(f"{i}/{total} - {key} from input2 not in input1.") + + i = 0 + total = len(lst_same_name_normalize) + for key in lst_same_name_normalize: + value1 = dct_project_1.get(key) + value2 = dct_project_2.get(key) + old_revision = value1.get("@revision", git_tool.default_branch) + new_revision = value2.get("@revision", git_tool.default_branch) + + path1 = value1.get("@path") + path2 = value2.get("@path") + if path1 != path2: + print(f"WARNING id {i}, path of git are different. " + f"Input1 {path1}, input2 {path2}") + continue + + i += 1 + result = "same" if old_revision == new_revision else "diff" + print(f"{i}/{total} - {result} - " + f"{path1} {key} old {old_revision} new {new_revision}") + default_arg = [f"{old_revision}..{new_revision}"] + if old_revision != new_revision: + # get git diff + repo = Repo(path1) + status = repo.git.diff(*default_arg) + print(status) + + +if __name__ == '__main__': + main() diff --git a/script/git_tool.py b/script/git_tool.py index 6fc7bb0..f9e9e37 100644 --- a/script/git_tool.py +++ b/script/git_tool.py @@ -18,6 +18,7 @@ CST_EL_GITHUB_TOKEN = "EL_GITHUB_TOKEN" DEFAULT_PROJECT_NAME = "ERPLibre" DEFAULT_WEBSITE = "erplibre.ca" DEFAULT_REMOTE_URL = "https://github.com/ERPLibre/ERPLibre.git" +DEFAULT_BRANCH = "12.0" class Struct(object): @@ -26,6 +27,22 @@ class Struct(object): class GitTool: + @property + def default_project_name(self): + return DEFAULT_PROJECT_NAME + + @property + def default_website(self): + return DEFAULT_WEBSITE + + @property + def default_remote_url(self): + return DEFAULT_REMOTE_URL + + @property + def default_branch(self): + return DEFAULT_BRANCH + @staticmethod def get_url(url: str) -> object: """ @@ -128,7 +145,6 @@ class GitTool: Get information about submodule from repo_path :param repo_path: path of repo to get information about submodule :param add_root: add information about root repository - :param upstream: Use this upstream of root :return: [{ "url": original_url, @@ -428,7 +444,7 @@ class GitTool: "Validate why 2 or more is not submodule.") lst_default.append(OrderedDict([ ('@remote', repo.original_organization), - ('@revision', "12.0"), + ('@revision', DEFAULT_BRANCH), ('@sync-j', "4"), ('@sync-c', "true"), ])) @@ -461,7 +477,7 @@ class GitTool: if default_remote and not lst_default: lst_default.append(OrderedDict([ ('@remote', default_remote), - ('@revision', "12.0"), + ('@revision', DEFAULT_BRANCH), ('@sync-j', "4"), ('@sync-c', "true"), ]))