Skip to content

Conversation

@perlpunk
Copy link
Collaborator

@perlpunk perlpunk commented Feb 2, 2016

This needs a bit more work.

See issue #28

After a successful command, delete GIT_HUB_MSG_FILE.
When starting editor and file exists, prompt for reusing, deleting
or aborting.

Still todo:

  • Only delete the file after commands that actually use
    the editor, so a non-editor-command wouldn't destroy an old file.
  • Delete when nothing was entered.
  • Show the age of the old file when prompting.
  • If reusing, replace the meta information with the one from the new command.

@perlpunk perlpunk force-pushed the issue/28-git-hub-msg-file branch 2 times, most recently from e5d5856 to 418c26e Compare February 5, 2016 19:05
@perlpunk
Copy link
Collaborator Author

perlpunk commented Feb 5, 2016

Implemented the missing todos.
I squashed everything to a single commit.

@perlpunk perlpunk force-pushed the issue/28-git-hub-msg-file branch from 418c26e to d5fa99c Compare February 5, 2016 19:12
@ingydotnet
Copy link
Owner

sweet!

@perlpunk
Copy link
Collaborator Author

perlpunk commented Feb 5, 2016

:D
I forgot to remove a comment line. pushed force

@perlpunk
Copy link
Collaborator Author

perlpunk commented Feb 5, 2016

btw: it will ignore old msg files, so when users upgrade, they won't get prompted because of old files from successful commands.

@ingydotnet
Copy link
Owner

Is there a way to detect and delete the old ones?

@perlpunk
Copy link
Collaborator Author

perlpunk commented Feb 5, 2016

I think it's not necessary to delete them.
But if you want, you can check for "# Command: " in the last line of the file (like it is done in init-msg-file), which is only there with the new code.

@perlpunk
Copy link
Collaborator Author

perlpunk commented Feb 5, 2016

another thing: when prompted, you can enter a, r or d. if the user enters something else, what should be done? abort?

delete comment lines from previous GIT_HUB_MSG_FILE
show date of GIT_HUB_MSG_FILE
only remove GIT_HUB_MSG_FILE when editor command was used
delete empty GIT_HUB_MSG_FILE
write new content into GIT_HUB_MSG_FILE in case of an old file
abort if user does not enter 'r' or 'd'
@perlpunk perlpunk force-pushed the issue/28-git-hub-msg-file branch from 1af1ecb to 715403d Compare February 7, 2016 13:49
@perlpunk
Copy link
Collaborator Author

perlpunk commented Feb 7, 2016

You were right, the old content was shown when there was an old
file. fixed.
Also, if the users enters something else than 'r' or 'd', it behaves
like 'a' (abort)

squashed commits

@ingydotnet
Copy link
Owner

Here is a test where I entered "foo\nbar\n" as my msg:

~/src/test-repo $ git hub issue

Error: malformed message in '.git/GIT_HUB_EDIT_MSG'

  Usage: git hub issue-new [<owner>/<repo>]

  Create a new issue for a repository.

~/src/test-repo $ git hub issue
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

.git/GIT_HUB_EDIT_MSG still exists, previous command probably wasn't successful.
The command was: 'git hub issue-new '
Date:
You can reuse or delete the old file.
(a)bort, (r)euse or (d)elete? a
~/src/test-repo $

The date failure is likely OSX specific. There are some OSX specific parts in
git-hub. Search for 'darwin'. Solve this in a similar fashion.

The command has an extra space at the end.

I'd like the prompt message to be:

Found existing GIT_HUB_EDIT_MSG from:

  command: '...'
  date:    ...

(r)euse, (s)how, (n)ew, (d)elete, (a)bort? 

Where 'show' runs something like head .git/GIT_HUB_EDIT_MSG | grep -v '^#'

And new opens a new message without deleting the old GIT_HUB_EDIT_MSG.

@perlpunk
Copy link
Collaborator Author

perlpunk commented Feb 7, 2016

  • changed the prompt message format.
  • added (s)how. it will prompt again after that

TODO:

  • I cannot figure out how to call date under osx. Well I have an idea with using stat but I cannot test
  • Opening a new file without deleting/overwriting the old one would require more changes because I'd have to use a different filename

@perlpunk perlpunk force-pushed the issue/28-git-hub-msg-file branch 2 times, most recently from f7edf2e to 3ec8eb9 Compare February 7, 2016 17:27
add possibility to show msg file and prompt again after that
@perlpunk perlpunk force-pushed the issue/28-git-hub-msg-file branch from 3ec8eb9 to 04a7b9c Compare February 7, 2016 18:57
@perlpunk
Copy link
Collaborator Author

perlpunk commented Feb 7, 2016

fixed the trailing whitespace

@perlpunk
Copy link
Collaborator Author

perlpunk commented Feb 7, 2016

Regarding choosing "new":
Choosing a new filename for the current file would make things more complicated. And it would get worse if the current command also fails, and so on.

I'd rather have the option to (s)ave the old file somewhere else, but this must be a unique filename in case this happens more than once. Like file.<timestamp>, or let the user choose a filename.

@perlpunk perlpunk force-pushed the issue/28-git-hub-msg-file branch from 508f129 to 4cae997 Compare February 7, 2016 19:42
@perlpunk
Copy link
Collaborator Author

perlpunk commented Feb 9, 2016

I added an OSX specific command for getting the date of the file.
please test =)

@ingydotnet
Copy link
Owner

Applied. Pushed. Thanks!

@ingydotnet ingydotnet closed this Feb 9, 2016
@ingydotnet
Copy link
Owner

Skipping (n)ew option or saveas for now.

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.

2 participants