oh-my-fish / oh-my-fish-legacy

Oh My Fish!
MIT License
13 stars 2 forks source link

Need an update guide #341

Closed amio closed 9 years ago

amio commented 9 years ago

I can cd ~/.oh-my-fish; git pull to update oh-my-fish, but is this a 'right' way? or maybe there should be a script for updating?

bpinto commented 9 years ago

It is the right way, but we can make it easier.

I have considered adding a update_oh_my_fish function that would go to $fish_path and run git pull --rebase automatically.

It also needs to handle update in the case a person installed oh-my-fish without git (downloading the zip from github).

bpinto commented 9 years ago

Want to give me a pull request adding this feature? It would be amazing.

ghost commented 9 years ago

:+1: Mmm sounds like fun.

amio commented 9 years ago

Let me have a try :)

bpinto commented 9 years ago

Let me know if I can help you with anything. :)

amio commented 9 years ago

Of course and thanks :) A little busy on office working these days, so I have some thoughts but not start it yet :P

bpinto commented 9 years ago

No rush, I was until today too. :+1:

ghost commented 9 years ago

@amio Hey how is it going? :)

amio commented 9 years ago

Just come back from company's yearly outing, I'll start it today or tommorrow :P

amio commented 9 years ago

How can I check if a git repo clean or dirty?

# this works fine, executing in terminal
# the command return 1 when the working directory is clean (may contain
# additional files but good to update)
$ git status --porcelain | grep "^[^ MADRC]"
?? functions/update_oh_my_fish.fish
# but I can't make it work inside a "if" block, 
# I must have something misunderstood with usage of "if" or "grep" > <
  if [ (git status --porcelain | grep "^[^ MADRC]") -eq 1 ]
    echo clean
  else
    echo dirty
  end
ghost commented 9 years ago

@amio Check this.

So, what exactly are you going to do? and what about something like?

$ update
...
Oh-My-Fish up to date.
amio commented 9 years ago

I want to check if the directory is clean for git pull

# This should be good to updating
$ git status --porcelain
?? a-new-file.txt

# Updating should abort when meet this
$ git status --porcelain
 M a-modified-file.txt
A  a-modified-and-indexed-file.txt
D  a-deleted-and-indexed-file.txt
ghost commented 9 years ago

If you are updating via git, just git --pull rebase upstream master should be fine IMO. I don't see what's the grand benefit of checking if the repo is dirty or not.

OK, I see you mean the local repo.

What about git ls-files --other --directory --exclude-standard?

bpinto commented 9 years ago

As far as I know, this is the fastest way to do it:

function _is_git_dirty
  echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
bobthecow commented 9 years ago

depending on what exactly you mean by "dirty", there are quite a "fastest ways" :)

https://github.com/bpinto/oh-my-fish/blob/master/themes/bobthefish/fish_prompt.fish#L284-L289

amio commented 9 years ago

Wow, thank you all!

@bucaran git ls-files is great! I never knew that :D Well it cannot figure out files in staging area, which could abort a git-pull operation:

$ git status -sb
## func-update-omf
A  functions/update_oh_my_fish.fish

$ git ls-files --other --directory --exclude-standard
# no output

@bpinto I finally figure out the echo append a \n to the end of output which cause if [ ( _is_git_dirty ) ] get a truthy value, so add a -n make it work:

function _is_git_touched
    echo -n (command git status --porcelain ^/dev/null | grep "^[ MADRCU]")
end

if [ -d .git ]
  if [ ( _is_git_touched ) ]
    git pull
  else
    # echo Do you want to overwrite local modification?
  end
end

@bobthecow Useful snippets :+1: I want to check if I can perform git-pull in the .oh-my-fish directory safely, so define 'dirty' as a situation that:

And, if only new file present:

$ git status -s
?? a-new-file-but-not-added-to-git-staging-area.txt

It won't be considered as 'dirty'.

so, I made it git status --porcelain ^/dev/null | grep "^[ MADRCU]", seems this works as I expected.