mirror of
https://github.com/oh-my-fish/oh-my-fish
synced 2024-11-09 13:10:40 +00:00
Merge pull request #18 from oh-my-fish/repo-functions
Add repo functions to omf utily
This commit is contained in:
commit
5fa0db56bf
@ -28,7 +28,7 @@ function omf.install -a type_flag name_or_url
|
||||
echo (omf::err)"Error: $local_name $install_type already installed."(omf::off) 1^&2
|
||||
else
|
||||
echo (omf::dim)"Trying to clone from URL..."(omf::off)
|
||||
if git clone -q $name_or_url $OMF_PATH/$parent_path/$local_name
|
||||
if omf.repo.clone $name_or_url $OMF_PATH/$parent_path/$local_name
|
||||
omf.persist $install_type $name_or_url
|
||||
_display_success "$install_type $name_or_url"
|
||||
else
|
||||
@ -41,12 +41,12 @@ function omf.install -a type_flag name_or_url
|
||||
if test -e $OMF_PATH/$target
|
||||
echo (omf::dim)"Updating $name_or_url $install_type..."(omf::off)
|
||||
pushd $OMF_PATH/$target
|
||||
omf.util_sync "origin" >/dev/null ^&1
|
||||
omf.repo.pull
|
||||
popd
|
||||
echo (omf::em)"✔ $name_or_url $install_type up to date."(omf::off)
|
||||
else
|
||||
echo (omf::dim)"Installing $name_or_url $install_type..."(omf::off)
|
||||
if git clone (cat $OMF_PATH/db/$target) $OMF_PATH/$target >/dev/null ^&1
|
||||
if omf.repo.clone (cat $OMF_PATH/db/$target) $OMF_PATH/$target
|
||||
omf.persist $install_type $name_or_url
|
||||
_display_success "$install_type $name_or_url"
|
||||
else
|
||||
|
3
pkg/omf/cli/omf.repo.clone.fish
Normal file
3
pkg/omf/cli/omf.repo.clone.fish
Normal file
@ -0,0 +1,3 @@
|
||||
function omf.repo.clone -a url path
|
||||
command git clone --quiet $url $path
|
||||
end
|
43
pkg/omf/cli/omf.repo.pull.fish
Normal file
43
pkg/omf/cli/omf.repo.pull.fish
Normal file
@ -0,0 +1,43 @@
|
||||
function omf.repo.pull
|
||||
if test (command git config --get remote.upstream.url)
|
||||
set repository upstream
|
||||
else
|
||||
set repository origin
|
||||
end
|
||||
|
||||
set initial_branch (command git symbolic-ref -q --short HEAD); or return $OMF_UNKNOWN_ERR
|
||||
set initial_revision (command git rev-parse -q --verify HEAD); or return $OMF_UNKNOWN_ERR
|
||||
|
||||
if not command git diff --quiet
|
||||
echo (omf::em)"Stashing your changes:"(omf::off)
|
||||
command git status --short --untracked-files
|
||||
|
||||
command git stash save --include-untracked --quiet
|
||||
set stashed true
|
||||
end
|
||||
|
||||
if test "$initial_branch" != master
|
||||
command git checkout master --quiet
|
||||
end
|
||||
|
||||
# the refspec ensures that '$repository/master' gets updated
|
||||
command git pull --rebase --quiet $repository "refs/heads/master:refs/remotes/$repository/master"
|
||||
if test $status -eq 2 #SIGINT
|
||||
command git checkout $initial_branch
|
||||
command git reset --hard $initial_revision
|
||||
test "$stashed" = true; and command git stash pop
|
||||
end
|
||||
|
||||
if test "$initial_branch" != master
|
||||
command git checkout $initial_branch --quiet
|
||||
end
|
||||
|
||||
if test "$stashed" = true
|
||||
command git stash pop --quiet
|
||||
|
||||
echo (omf::em)"Restored your changes:"(omf::off)
|
||||
command git status --short --untracked-files
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
@ -1,16 +0,0 @@
|
||||
function omf.update
|
||||
set -l repo "upstream"
|
||||
test -z (git config --get remote.upstream.url)
|
||||
and set -l repo "origin"
|
||||
|
||||
if git diff-index --quiet HEAD -- >/dev/null ^&1
|
||||
git pull $repo master >/dev/null ^&1
|
||||
else
|
||||
git stash >/dev/null ^&1
|
||||
if git pull --rebase $repo master >/dev/null ^&1
|
||||
git stash apply >/dev/null ^&1
|
||||
else
|
||||
omf.util_sync "origin"
|
||||
end
|
||||
end
|
||||
end
|
@ -125,7 +125,7 @@ function omf -d "Oh My Fish"
|
||||
case "u" "up" "upd" "update"
|
||||
pushd $OMF_PATH
|
||||
echo (omf::em)"Updating Oh My Fish..."(omf::off)
|
||||
if omf.update
|
||||
if omf.repo.pull
|
||||
echo (omf::em)"Oh My Fish is up to date."(omf::off)
|
||||
else
|
||||
echo (omf::err)"Oh My Fish failed to update."(omf::off)
|
||||
|
@ -1,4 +0,0 @@
|
||||
function omf.util_fork_repo -a user repo
|
||||
curl -u "$user" --fail --silent https://api.github.com/repos/$repo/forks \
|
||||
-d "{\"user\":\"$user\"}" >/dev/null ^&1
|
||||
end
|
@ -1,8 +0,0 @@
|
||||
function omf.util_sync -a remote
|
||||
set -l repo $remote
|
||||
set -q argv[1]; and set repo $argv[1]
|
||||
|
||||
git fetch origin master
|
||||
git reset --hard FETCH_HEAD
|
||||
git clean -df
|
||||
end
|
Loading…
Reference in New Issue
Block a user