From df20117be7a789efe0a91fdd4a7ae377358f3e1e Mon Sep 17 00:00:00 2001 From: YangKeao Date: Fri, 22 Jan 2021 20:02:03 +0800 Subject: [PATCH] Add branch information for install and update package (#685) * Install package according to branch information in repo * Add branch information for update package * add double quotes for $branch Signed-off-by: Yang Keao --- .../packages/omf.packages.install.fish | 8 +++++-- .../packages/omf.packages.update.fish | 9 +++++++- pkg/omf/functions/repo/omf.repo.clone.fish | 4 ++-- pkg/omf/functions/repo/omf.repo.pull.fish | 22 ++++++++----------- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/pkg/omf/functions/packages/omf.packages.install.fish b/pkg/omf/functions/packages/omf.packages.install.fish index d8f6508..75ffe30 100644 --- a/pkg/omf/functions/packages/omf.packages.install.fish +++ b/pkg/omf/functions/packages/omf.packages.install.fish @@ -11,10 +11,14 @@ function __omf.packages.install.error.already end function omf.packages.install -a name_or_url - if set -l props (omf.index.stat $name_or_url type repository) + if set -l props (omf.index.stat $name_or_url type repository branch) set package_type $props[1] set name $name_or_url set url $props[2] + set branch $props[3] + if test -z "$branch" + set branch "master" + end else set name (omf.packages.name $name_or_url) set url $name_or_url @@ -30,7 +34,7 @@ function omf.packages.install -a name_or_url set -l install_dir $OMF_PATH/pkg/$name # Clone the package repository. - if not omf.repo.clone $url $install_dir + if not omf.repo.clone $url $branch $install_dir __omf.packages.install.error "$name" return $OMF_UNKNOWN_ERR end diff --git a/pkg/omf/functions/packages/omf.packages.update.fish b/pkg/omf/functions/packages/omf.packages.update.fish index 4897a02..67edbac 100644 --- a/pkg/omf/functions/packages/omf.packages.update.fish +++ b/pkg/omf/functions/packages/omf.packages.update.fish @@ -1,4 +1,11 @@ function omf.packages.update -a name + if set -l props (omf.index.stat $name branch) + set branch $props[1] + if test -z "$branch" + set branch "master" + end + end + if not set target_path (omf.packages.path $name) echo (omf::err)"Could not find $name."(omf::off) >&2 return 1 @@ -6,7 +13,7 @@ function omf.packages.update -a name # Only pull packages in version control if test -e $target_path/.git - omf.repo.pull $target_path + omf.repo.pull $target_path "$branch" switch $status case 0 omf.bundle.install $target_path/bundle diff --git a/pkg/omf/functions/repo/omf.repo.clone.fish b/pkg/omf/functions/repo/omf.repo.clone.fish index 2a2d9ef..beba8d4 100644 --- a/pkg/omf/functions/repo/omf.repo.clone.fish +++ b/pkg/omf/functions/repo/omf.repo.clone.fish @@ -1,3 +1,3 @@ -function omf.repo.clone -a url path - command git clone --quiet $url $path +function omf.repo.clone -a url branch path + command git clone --quiet $url -b $branch $path end diff --git a/pkg/omf/functions/repo/omf.repo.pull.fish b/pkg/omf/functions/repo/omf.repo.pull.fish index 4b6b800..7564fd2 100644 --- a/pkg/omf/functions/repo/omf.repo.pull.fish +++ b/pkg/omf/functions/repo/omf.repo.pull.fish @@ -1,12 +1,8 @@ -function omf.repo.pull - - if test (count $argv) -eq 0 - echo (omf::err)"omf.repo.pull takes a repository path as an argument."(omf::off) >&2 - return $OMF_MISSING_ARG +function omf.repo.pull -a repo_dir branch + if test -z "$branch" + set branch "master" end - set -l repo_dir $argv[1] - function __omf.repo.git -V repo_dir command git -C "$repo_dir" $argv end @@ -21,12 +17,12 @@ function omf.repo.pull set initial_revision (__omf.repo.git rev-parse -q --verify HEAD); or return 1 - # the refspec ensures that '$remote/master' gets updated - set -l refspec "refs/heads/master:refs/remotes/$remote/master" + # the refspec ensures that '$remote/$branch' gets updated + set -l refspec "refs/heads/$branch:refs/remotes/$remote/$branch" __omf.repo.git fetch --quiet $remote $refspec; or return 1 - if test (__omf.repo.git rev-list --count master...FETCH_HEAD) -eq 0 + if test (__omf.repo.git rev-list --count "$branch"...FETCH_HEAD) -eq 0 return 2 end @@ -37,8 +33,8 @@ function omf.repo.pull and set stashed end - if test "$initial_branch" != master - __omf.repo.git checkout master --quiet + if test "$initial_branch" != "$branch" + __omf.repo.git checkout "$branch" --quiet end if not __omf.repo.git merge --ff-only --quiet FETCH_HEAD @@ -48,7 +44,7 @@ function omf.repo.pull return 1 end - if test "$initial_branch" != master + if test "$initial_branch" != "$branch" __omf.repo.git checkout $initial_branch --quiet end