Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path related bugs. #58

Merged
merged 2 commits into from
Nov 23, 2019
Merged

Fix path related bugs. #58

merged 2 commits into from
Nov 23, 2019

Conversation

wfxr
Copy link
Owner

@wfxr wfxr commented Nov 22, 2019

Description

Fix some path related bugs. Add status indicator to forgit::diff command BTW.

Type of change

Please delete options that are not relevant.

  • Bug fix
  • (Minor) Feature : Add status indicator to forgit::diff command BTW.
  • (Minor) Breaking change : Paths listed by forgit::diff will now use repo's root as the start point.

Shells this fix should effect:

  • bash
  • zsh
  • fish

Shells this fix has been tested in:

  • bash
  • zsh
  • fish

Test Configuration:

  • OS: Arch Linux x86_64

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Related issue(s):

#39 : This pr will remove the dependency on realpath.

Please help sync the fish version. @cjappl

@cjappl
Copy link
Collaborator

cjappl commented Nov 22, 2019

Cool! I see this. I will get a commit in as soon as I can. I am on vacation so it may be a few days :)

@wfxr
Copy link
Owner Author

wfxr commented Nov 22, 2019

@cjappl No rush. Take your time :)

BREAKING CHANGE: 🧨 Paths listed by forgit::diff will use repo's root as start point.
@@ -63,7 +64,7 @@ forgit::add() {
"
files=$(git -c color.status=always -c status.relativePaths=true status --short |
grep -F -e "$changed" -e "$unmerged" -e "$untracked" |
awk '{printf "[%10s] ", $1; $1=""; print $0}' |
sed 's/^\(..[^[:space:]]*\)[[:space:]]\+\(.*\)$/[\1] \2/' |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wfxr, working on this now, but want to be 100% sure I'm understanding what this is before I put it in!

Can you explain what this sed command, and the sed command up top do? I'm not super well versed on sed

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here regular expressions are used for capturing and replacing.

If you remove the escape character it will look a bit clearer:
sed 's/^(..[^[:space:]]*)[[:space:]]+(.*)$/[\1] \2/'.

What this line does is to capture the status indicator at the beginning of the line, surround it with square brackets, then append the full path. Completely explaining sed's regex rules is not easy. But you can test it to see how it works:

# go to `forgit`'s local repo
touch 'a          b   c'
echo 'hello world!' >> README.md

# buggy
git status --short | awk '{printf "[%10s]  ", $1; $1=""; print $0}'

# fixed
git status --short | sed 's/^\(..[^[:space:]]*\)[[:space:]]\+\(.*\)$/[\1]  \2/'

@wfxr wfxr mentioned this pull request Nov 26, 2019
15 tasks
@ea2809 ea2809 mentioned this pull request Dec 16, 2019
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants