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

Auto Notify Git Pull #7

Closed
wants to merge 8 commits into from
Closed

Auto Notify Git Pull #7

wants to merge 8 commits into from

Conversation

hemanth
Copy link
Contributor

@hemanth hemanth commented Jul 11, 2013

Fixes issue #6

@@ -63,6 +63,14 @@ precmd() {
unset cmd_timestamp
}

# Auto notify git pull!
function chpwd() {
emulate -L zsh
Copy link
Owner

Choose a reason for hiding this comment

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

why? what does it do? we're already in zsh

@sindresorhus
Copy link
Owner

Shouldn't this be async like the one in your blog post?

Can you fix merge conflict?

@hemanth
Copy link
Contributor Author

hemanth commented Jul 11, 2013

@sindresorhus chpwd seems to be faster than bash, so async is not needed? will fix the conflicts soon!

@hemanth
Copy link
Contributor Author

hemanth commented Jul 12, 2013

@sindresorhus Was speaking to few git experts they says (( $(git rev-list HEAD..@{u} --count) > 0 )) && echo "There are new things to merge" is a better way and a better message. Also it's only slow with cold cache.

There was also a suggestion to use backdoor, what do you suggest?

@sindresorhus
Copy link
Owner

(( $(git rev-list HEAD..@{u} --count) > 0 )) && echo "There are new things to merge" is a better way

Go for it.

HEAD..@{u}

What does this mean?

There was also a suggestion to use backdoor, what do you suggest?

Can you explain what it does and why it's needed?

@hemanth
Copy link
Contributor Author

hemanth commented Jul 13, 2013

HEAD..@{u}

Is better than using HEAD...origin/master as it looks for all other branches and the .. and ... is commint-range . It can be even simpler git rev-list ..@{u} --count :)

Backdoor was suggested to emulate async process, but it was also clear that in this case async is not needed for zsh as it's only slow with cold cache.

@sindresorhus
Copy link
Owner

Backdoor was suggested to emulate async process, but it was also clear that in this case async is not needed for zsh as it's only slow with cold cache.

Interesting. Since it's async, how does it add the message when it returns? Like, what if i write something before it's shown. Not important here, but the git branch and dirty check can be slow in large repos. Wonder if it would be possible to use it there? Like, can it dynamically update the prompt?

@hemanth
Copy link
Contributor Author

hemanth commented Jul 13, 2013

It just uses FD hack to simulate async, it does not have a callback as such, but /me needs to explore it more to see if it can dynamically update the prompt.

@sindresorhus
Copy link
Owner

ping

@hemanth
Copy link
Contributor Author

hemanth commented Aug 7, 2013

Sorry for the delay! For something like dynamic update of the prompt, we could use this function with setopt PROMPT_SUBST

@sindresorhus
Copy link
Owner

k, can you fix the merge conflict?

@hemanth
Copy link
Contributor Author

hemanth commented Aug 12, 2013

@sindresorhus It must be 🍏 now :)

@sindresorhus
Copy link
Owner

Tried it now. It only works after I do git fetch, which kinda destroys it all. Can you fix?

@hemanth
Copy link
Contributor Author

hemanth commented Aug 13, 2013

@sindresorhus Fine now?

@sindresorhus
Copy link
Owner

@hemanth look at the diff here, no change.

I also discovered another bug. If the repo doesn't have a remote it will throw up:

fatal: ambiguous argument 'HEAD...origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'

@hemanth
Copy link
Contributor Author

hemanth commented Aug 16, 2013

@sindresorhus fix is to add the remote origin and do a rebase again?

@sindresorhus
Copy link
Owner

I don't understand the question?

@hemanth
Copy link
Contributor Author

hemanth commented Aug 19, 2013

@sindresorhus Ha ok, I misunderstood it as an issue with merging, will work on it!

@willdurand
Copy link

👍

@sindresorhus
Copy link
Owner

Can we get this finished too? I have 🐫

@hemanth
Copy link
Contributor Author

hemanth commented Sep 4, 2013

Sure!

Working on :

If the repo doesn't have a remote....

@sindresorhus
Copy link
Owner

ping

@hemanth
Copy link
Contributor Author

hemanth commented Sep 13, 2013

@sindresorhus This shall be closed at any cost today! Sorry for this great delay!

@hemanth
Copy link
Contributor Author

hemanth commented Sep 13, 2013

@sindresorhus Done, used a simple redirection, branch --set-upstream could also be used.

@sindresorhus
Copy link
Owner

Tried it now. It only works after I do git fetch, which kinda destroys it all.

@hemanth
Copy link
Contributor Author

hemanth commented Sep 13, 2013

@sindresorhus Was wondering the same, git rev will assume a git fetch and does not go online, will that be fine for this scenario ? Or maybe should we stick to git ls-remote or git pull --dry-run or similar?

@sindresorhus
Copy link
Owner

@hemanth having to do git fetch first makes it pretty useless.

So, it's possible to use git ls-remote to do the same?

git pull --dry-run

git pull doesn't have a dry run.

Another solution would be to just do a git fetch, then run the current code, though I would prefer git ls-remote if it's possible to use it.

@pbrisbin thoughts?

@pbrisbin
Copy link
Contributor

Hmm, I think it's a non-starter. This can't be done without somehow reaching out to the remote, and I don't want my prompt doing that all day long. If it were implemented, I'd quickly make a PR to add a disabling option ;).

I'm just one datapoint, but that's my 2c.

@sindresorhus
Copy link
Owner

What's wrong with reaching out to the remote if it happens transparently in the background?

Option ofc.

@pbrisbin
Copy link
Contributor

If it's not done async (and this PR is not), then the delay is not transparent.

If it is done async, then there is very good likelihood of this:

~/Code/foo master
> vim src/maYou have stuff to pull..
in.c

@sindresorhus
Copy link
Owner

Isn't it possible to manipulate readline or something to get this:

~/Code/foo master  You have stuff to pull..
> vim src/main.c

@pbrisbin
Copy link
Contributor

Isn't it possible to...

I like this prompt because it's minimal, fast, and cleanly implemented (tabs and comments not withstanding ;)). In my opinion, this feature is not worth the impact it'd have on those three things.

Again, just my 2c though.

@hemanth
Copy link
Contributor Author

hemanth commented Sep 14, 2013

@sindresorhus I'm pawing at git ls-remote

@pbrisbin There was also a suggestion to use backdoor for async, if you scroll up. But this was not blocking the shell in any way with precmd, in case it does, any other suggestions for async?

@sindresorhus
Copy link
Owner

Closing in favor of #18.

@hemanth Thanks for the awesome idea :)

@hemanth
Copy link
Contributor Author

hemanth commented Sep 17, 2013

@sindresorhus 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants