Skip to content

Commit

Permalink
use a default "fetch" strategy (#195)
Browse files Browse the repository at this point in the history
up until now, the default `strategy` for `gm repo branch fetch` has been
`none`, which implies that, to have a proper "fetch strategy",
`--strategy <strat>` had to be used every time...

however, in my Git config, i have `pull.rebase` set to `true`, which
means i want to _rebase_ most of the time.

this PR makes it so that the default value of `strategy: string` is
either `rebase` when `pull.rebase` is set or `merge` when it's not.

the "strategy" can always be
- overwritten with `--strategy rebase` or `--strategy merge`
- disabled with `--strategy none`
  • Loading branch information
amtoine authored Apr 28, 2024
1 parent a2aec66 commit 6cdfe07
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-bisect.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo bisect` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L435))
# `gm repo bisect` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L440))
bisect a worktree by running a piece of code repeatedly

# Examples
Expand Down
3 changes: 2 additions & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-branch-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ fetch a remote branch locally, without pulling down the whole remote
## Parameters
- `remote` <`string@get-remotes`>: the branch to fetch
- `branch` <`string@get-branches`>: the remote to fetch the branch from
- `--strategy` <`string@get-strategies`> = `none`: the merge strategy to use
- `--strategy` <`string@get-strategies`>: the merge strategy to use, defaults to the `pull.rebase` Git
config option


## Signatures
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo branch interactive-delete` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L281))
# `gm repo branch interactive-delete` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L286))
remove a branch interactively


Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-ls.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo ls` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L325))
# `gm repo ls` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L330))
get some information about a repo


Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-query.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo query` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L375))
# `gm repo query` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L380))
queries the `.git/` directory as a database with `nu_plugin_git_query`

## Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-switch.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo switch` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L301))
# `gm repo switch` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L306))
switch between branches interactively


Expand Down
7 changes: 6 additions & 1 deletion pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,13 @@ export def "gm repo remote add" [name: string, remote: string, --ssh]: nothing -
export def "gm repo branch fetch" [
remote: string@get-remotes, # the branch to fetch
branch: string@get-branches, # the remote to fetch the branch from
--strategy: string@get-strategies = "none" # the merge strategy to use
--strategy: string@get-strategies # the merge strategy to use, defaults to the `pull.rebase` Git
# config option
]: nothing -> nothing {
let strategy = $strategy | default (
if (^git config pull.rebase) == "true" { "rebase" } else { "merge" }
)

^git fetch $remote $branch

if (^git branch --list | lines | str substring 2.. | where $it == $branch | is-empty) {
Expand Down
6 changes: 3 additions & 3 deletions pkgs/nu-git-manager-sugar/tests/git.nu
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export def branch-fetch [] {

do {
cd $bar
gm repo branch fetch $"file://($foo)" foo
gm repo branch fetch $"file://($foo)" foo --strategy none

assert simple-git-tree-equal [
"(foo) c2",
Expand All @@ -159,7 +159,7 @@ export def branch-fetch [] {

do {
cd $bar
gm repo branch fetch $"file://($foo)" foo
gm repo branch fetch $"file://($foo)" foo --strategy none

assert simple-git-tree-equal [
"(foo) c4",
Expand All @@ -176,7 +176,7 @@ export def branch-fetch [] {

do {
cd $bar
gm repo branch fetch $"file://($foo)" foo
gm repo branch fetch $"file://($foo)" foo --strategy none

assert simple-git-tree-equal --extra-revs ["FETCH_HEAD"] [
"c6",
Expand Down

0 comments on commit 6cdfe07

Please sign in to comment.