Граф коммитов

101 Коммитов

Автор SHA1 Сообщение Дата
Mike Lundy c4dfa597b8
add /v2 to the module name to resolve the module path problem 2020-04-16 16:30:07 -07:00
kfcampbell 8db8f617d1 Merge master to resolve merge conflict. 2020-04-13 10:09:50 -07:00
lufia 95f8bb72be Replace bmizerany/assert with internal/assert 2020-04-03 16:54:01 +09:00
kfcampbell f7d08865e0 Partial lint rest of github folder. 2020-03-20 16:11:23 -07:00
Mislav Marohnić 64cfcdd19e Use `git symbolic-ref` to read the branch name for HEAD
This affects reading the current branch as well as reading the default
branch for a remote. Because we're no longer trying to read the ref
manually from the filesystem, this approach works with git worktrees.
2020-03-01 10:52:11 +01:00
Mislav Marohnić 2da8235c10 [remotes] Fix parsing `~/.ssh/config` on Windows
Use `homedir.Dir()` instead of `Getenv("HOME")` on Windows to look up
`~/.ssh/config` in the correct location.
2019-09-20 22:43:59 +02:00
Christian Muehlhaeuser 2fdb738a9d
Fixed ineffectual assignments in tests
Don't assign values we don't end up checking.
2019-07-23 09:31:17 +02:00
Mislav Marohnić 039afea3c6 Only process stdout when shelling out to git
For stderr, either attach it to parent stderr or silence it completely.
This enables GIT_TRACE.
2019-05-08 20:51:49 +02:00
Mislav Marohnić 7642e5b973 Support git versions that don't recognize --no-verbose 2018-12-11 10:30:24 +00:00
Jacob Bednarz 9bb5ffa9e7
Restore pre-2.20.0 `git help` output
After upgrading to Git 2.20.0, all operations that relied on `hub alias`
would indefinitely hang. It can be reproduced using the following:

1. Create a new alias such as `st` for `git status`.
2. Run `hub <alias>` in a git repository.

  ```
  $ hub st

  ... hangs forever
  ```

Inspecting the running process shows that it is executing `git help -a`
and not able to proceed. Digging into the `hub` shows that the `help`
command is called within `IsBuiltInGitCommand`. Once this entrypoint was
found, I started bisecting and found this works in 2.19.x but fails in
2.20.x. Sure enough, the Git 2.20.0 release notes mention a
corresponding change[1].

>  * "git help -a" now gives verbose output (same as "git help -av").
>    Those who want the old output may say "git help --no-verbose -a".

It was even nice enough to include the backwards compatibility fix :)

To fix the hanging, I've restored the existing behaviour by including
the `--no-verbose` flag that mimics the 2.19.x behaviour.

Fixes #1963

[1]: https://github.com/git/git/blob/master/Documentation/RelNotes/2.20.0.txt#L17-L18
2018-12-11 09:33:46 +11:00
Mislav Marohnić 6d7f6c1a45 Allow specifying a literal `%h` in `HostName` ssh config 2018-11-09 15:17:53 +01:00
Mislav Marohnić 5886837431 Expand tokens found in ssh config `HostName`
Per "TOKENS" section in ssh_config(5)

Fixes #1936
2018-11-09 12:52:04 +01:00
Mislav Marohnić 70e63ece56 No commit signature in default pull request message
Fixes #1379
2018-01-29 22:40:36 +01:00
Mislav Marohnić 6da6cf59ff Implement support for `core.commentchar=auto`
117ddefdb4/builtin/commit.c (L633)
2017-07-31 18:11:11 +02:00
Mislav Marohnić 4837835d6d Refactor how commented sections are added to contents of text editor
Before, the code outside of `editor.go` was responsible for prefixing
lines of the commented section with the comment char. The code to do
this was scattered all over the codebase and was difficult to refactor
re: adding support for `commentchar=auto`.

Now, Editor has a `AddCommentedSection()` method that allows for
declarative adding of a commented section. Furthermore, the caller
doesn't have to query git to determine the comment char.
2017-07-31 17:33:41 +02:00
Mislav Marohnić 7548421208 Show hub version even if `git version` fails
Fixes https://github.com/github/hub/issues/1423
2017-06-26 20:22:11 +02:00
Mislav Marohnić 01c3099abe Fix crash in `WorkdirName` when within bare git repo
`git rev-parse --show-toplevel` returns an empty string with success
status when inside a bare git repo.

This avoids the go crash and also tweaks `hub issue` and `hub
pull-request` to work even if current working directory name couldn't be
obtained because it's only used for looking up issue/PR templates, which
isn't critical functionality.

Fixes https://github.com/github/hub/issues/1331
2017-06-26 20:22:11 +02:00
Goel 3792b5e7f9 Do not expand aliases which are in-built git and hub commands 2016-11-07 14:30:45 +01:00
Mislav Marohnić ce24b1cf7e New `hub sync` command to update local branches
Ported from my bash version over at
370154a5ad/bin/git-sync
2016-09-12 06:29:53 +02:00
Mislav Marohnić 0c4689c673 Fix printing content on Windows after successful run
The old `args.After("echo", ...)` approach won't cut it on Windows since
there is no `echo` executable. Thus, nothing was printed on Windows.

Instead, expand Args type with extra functionality that allows Go
callbacks after all commands in the chain have been run.

Also, the new `args.NoForward()` is now preferred to `os.Exit()` since
it's more descriptive and allows `defer` in the calling function.
2016-09-10 23:49:58 +02:00
Mislav Marohnić 910dfdcb50 Negate `log.showSignature` in commits preview for `pull-request`
Fixes #1254
2016-09-09 01:22:19 +02:00
Mislav Marohnić e7f5c55e43 Expand environment variables in GIT_EDITOR value
This matches git behavior. Fixes #835
2016-08-07 23:55:56 +02:00
Mislav Marohnić c25e33e2db Fix case when multiple Enterprise hosts are configured
We only ever read the first hostname from the list because we didn't use
`git config --get-all`.

Fixes #1188
2016-07-12 16:32:25 +02:00
Mislav Marohnić 0d3617fd25 Infer project name from git workdir root name instead of PWD
The `create` and `remote` commands needs to infer the current project
name from the project's directory. Instead of using the current working
directory, which doesn't necessarily match the project's toplevel
directory, use `git rev-parse --show-toplevel` which also respects the
`-C` global flag setting.

Fixes #1105, closes #1114
2016-02-28 20:51:21 +09:00
Mislav Marohnić 9c9ff2d341 go fmt 2016-01-25 02:20:49 +11:00
Mislav Marohnić 7bb983648d Append to `git help` output instead of hardcoding it 2016-01-22 22:47:17 +11:00
Mislav Marohnić c3ddec3248 Improve detecting local clone resources
In `hub clone NAME`, "NAME" was previously considered a local resource
if a directory of the same name existed, and the clone command was left
unchanged.

That worked for a while, but some users were surprised that they
couldn't clone their repo named "NAME", only to discover that there was
an unrelated directory "NAME" in the current working directory.

Also, a git bundle is a valid cloneable resource, but is a file and not
a directory.

This refines the detection of cloneable resources. "NAME" is considered
to be locally cloneable if one of the following is true:

- "NAME/.git" exists
- "NAME" is a bare git repo
- "NAME" is a file whose first line includes "git bundle"
2016-01-22 20:47:51 +11:00
Mislav Marohnić 19017f9300 Merge branch 'go-1.5-vendor-experiment' 2016-01-22 16:01:10 +11:00
Mislav Marohnić b33ab4f466 Handle all sorts of weird git remote URLs
- git+ssh://github.com/...
- ssh://github.com:22/...
- git@github.com:/...

Fixes #876
2016-01-22 01:28:31 +11:00
Mislav Marohnić 1b862e3388 Switch from godep & rewriting import paths to GO15VENDOREXPERIMENT 2016-01-20 14:46:44 +11:00
Mislav Marohnić 1202fc4d39 Merge pull request #1024 from github/cache-git-dir
Cache result of `git rev-parse --git-dir`
2015-11-04 11:19:04 +01:00
Madhusudan.C.S 29317d283e Add unit tests for git.Remotes() and github.Remotes().
Also, define AddRemote() method for test Repo fixture.
2015-11-02 15:55:05 -08:00
Mislav Marohnić e6823e8d18 Cache result of `git rev-parse --git-dir`
It's invoked often from different methods, but always has the same
results. Cache it after the 1st run so subsequent runs are no-ops.

Before:

    HUB_VERBOSE=1 git browse
    $ git config alias.browse
    $ git rev-parse -q --git-dir
    $ git rev-parse -q --git-dir
    $ git remote -v
    $ git rev-parse -q --git-dir
    $ git config hub.host
    $ git rev-parse -q --git-dir
    $ git config push.default
    $ git rev-parse -q --git-path refs/remotes/origin/no-angular
    $ git rev-parse -q --git-dir
    $ git rev-parse -q --git-dir
    $ git rev-parse -q --git-dir

After (6 fewer invocations):

    HUB_VERBOSE=1 git browse
    $ git config alias.browse
    $ git rev-parse -q --git-dir
    $ git remote -v
    $ git config hub.host
    $ git config push.default
    $ git rev-parse -q --git-path refs/remotes/origin/no-angular
2015-10-31 18:05:37 +01:00
Mislav Marohnić 923402ad1a Go formatting fixes
[ci skip]
2015-10-31 01:52:17 +01:00
Mislav Marohnić b51be1cfba Properly support `-C` git global flag
From git documentation:

    -C <path> : Run as if git was started in <path> instead of the
                current working directory. When multiple -C options are
                given, each subsequent non-absolute -C <path> is
                interpreted relative to the preceding -C <path>.

We correctly forwarded the `-C <path>` values as git global flags to git
invocations such as `git rev-parse --git-dir`, but that command is
designed to return the result as a relative path to the value computed
from `-C`. This adds an extra step to transform this relative path to an
absolute one by applying values of `-C` as the base directory.
2015-10-31 01:43:28 +01:00
Mislav Marohnić 0e1ae6fd6e Detect `git rev-parse` output when on git version < 2.5
We can't use `--git-path` on git versions older than 2.5. Those versions
will simply echo `--git-path` as the first line of the output. Instead
of stat'ing that as a file, skip this case and proceed immediately to
fallback for other git versions.
2015-09-26 17:58:15 +02:00
Jason Zaugg bb550cecb3 Handle git worktrees when computing the head repo
Git 1.5.0 introduces support for worktrees. A worktree has a
.git file, rather than a folder. (The file contents points to to a
.git folder buried underneath the .git folder of the main repository.)

A new option has been added to resolve paths within the git dir,
`git rev-parse --git-path foo/bar`.

The commit uses this new facility, but falls back to the old approach
for backwards compability.

Fixes #969
2015-09-26 17:58:05 +02:00
Will Maier 74dcadf4f8 Fix spurious test failure when GIT_EDITOR is set
`git var` checks the `$GIT_EDITOR` environment variable before the `core.editor` config knob. `TestGitDir` intends to verify that the latter is respected, so sanitize the environment before running the test and restore it upon completion.
2015-07-07 04:17:20 +00:00
Jingwen Owen Ou 875b456f0c Check for empty git config
This fixes #858
2015-04-06 14:10:34 -07:00
Jean-Charles Sisk c1ad7a0ad9 make ssh config reader case-insensitive 2015-03-03 19:06:10 -05:00
Jingwen Owen Ou 2699a6b718 Parse more global flags from by following https://github.com/github/hub/blob/1.12-stable/lib/hub/commands.rb#L961-L995 2015-01-14 09:34:04 -08:00
Jingwen Owen Ou 546363d5c9 Rename `execGitCmd` to `gitOutput` 2015-01-12 22:13:23 -08:00
Jingwen Owen Ou 15be76697c Preserve global config flags specified with `-c` 2015-01-12 22:13:08 -08:00
Jingwen Owen Ou 4cb663a968 Rename `Cmd.ExecOutput` to `Cmd.CombinedOutput` to avoid confusion
We now have `Cmd.Spawn` and `Cmd.Exec`, to avoid confusion, we use `Cmd.CombinedOutput` for combined output.
2014-11-30 12:16:53 -08:00
Jingwen Owen Ou 0ed14758b7 Use `Exec` except Windows for the last command run in the commands chain
This is to avoid the interrupt/pagination issues like https://github.com/github/hub/issues/708. Note that `exec(3)` is not available on Windows: http://golang.org/src/pkg/syscall/exec_windows.go#L339. A fall to `spawn(3)` is used in this case.
2014-11-30 12:14:18 -08:00
Jingwen Owen Ou 8cd1ba849d Rename `Cmd.Exec` to `Cmd.Spawn`
This is to `spawn` a process not to `exec` one
2014-11-30 11:15:13 -08:00
Jingwen Owen Ou 6137851f15 Vendor dependencies by rewriting import paths 2014-11-30 09:16:57 -08:00
Jingwen Owen Ou 44d1fa7f48 Fix Go tests on Windows
A couple of Go tests failure on Windows, fix code or tests to make them green:

--- FAIL: TestSaveAlwaysReportOption (0.15 seconds)
panic: remove C:\Users\IEUser\AppData\Local\Temp\test-repo999546479\test.git: Th
e process cannot access the file because it is being used by another process. [r
ecovered]
        panic: remove C:\Users\IEUser\AppData\Local\Temp\test-repo999546479\test
.git: The process cannot access the file because it is being used by another pro
cess.

--- FAIL: TestRunnerCallCommands (0.00 seconds)
        assert.go:15: V:/src/github.com/github/hub/commands/runner_test.go:42
        assert.go:24: ! 0 != 1

--- FAIL: TestEditor_openAndEdit_deleteFileWhenOpeningEditorFails (0.00 seconds)
        assert.go:15: V:/src/github.com/github/hub/github/editor_test.go:34
        assert.go:36: !  Failure

--- FAIL: TestGitHubRepo_OriginRemote (0.16 seconds)
        assert.go:15: V:/src/github.com/github/hub/github/localrepo_test.go:18
        assert.go:24: ! "V:\\src\\github.com\\github\\hub\\fixtures\\test.git" !
= "ssh://V/%5Csrc%5Cgithub.com%5Cgithub%5Chub%5Cfixtures%5Ctest.git"
2014-11-20 19:36:32 -08:00
Jingwen Owen Ou 95bd9440df Ignore looking into ssh config if URL scheme is http or https
See https://github.com/github/hub/issues/681
2014-11-16 12:21:56 -08:00
Jingwen Owen Ou aab2e5f9d3 Ignore replacing ssh host that fixes limited network
ssh.github.com is a hack for people on limited networks to be able to use SSH through HTTPS port. We should ignore replacing it when constructing URLs.

As part of the fix, refactor into SSHConfig and SSHConfigReader to make code testable. It also fixes a bug on `hostReStr` that doesn’t match the “Hostname” string in ssh config.

Issue: https://github.com/github/hub/issues/672
2014-11-03 08:42:00 -08:00