Skip to content

Commit

Permalink
Update remote repo variables
Browse files Browse the repository at this point in the history
%(repo:remote) = the remote name only
%(repo:upstream) = the former %(repo:remote) with the upstream branch name

This introduces an incompatibility with previous versions.

Closes #1358
  • Loading branch information
koutcher committed Dec 3, 2024
1 parent 013c411 commit 039abe7
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 16 deletions.
4 changes: 4 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Release notes
master
------

Incompatibilities:

- Update remote repo variables. (#1358)

Bug fixes:

- Fix various issues with `diff.noprefix` and `--no-prefix`.
Expand Down
6 changes: 4 additions & 2 deletions doc/manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ following variables.
|%(text) |The text column of the currently selected line.
|%(repo:head) |The name of the checked out branch, e.g. `master`
|%(repo:head-id) |The commit ID of the checked out branch.
|%(repo:remote) |The remote associated with the checked out branch,
e.g. `origin/master`.
|%(repo:remote) |The remote name associated with the checked out
branch, e.g. `origin`.
|%(repo:upstream) |The upstream branch associated with the checked out
branch, e.g. `origin/master`.
|%(repo:cdup) |The path to change directory to the repository root,
e.g. `../`
|%(repo:prefix) |The path prefix of the current work directory,
Expand Down
6 changes: 4 additions & 2 deletions doc/tigrc.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,10 @@ following variable names, which are substituted before commands are run:
|%(text) |The text column of the currently selected line.
|%(repo:head) |The name of the checked out branch, e.g. `master`
|%(repo:head-id) |The commit ID of the checked out branch.
|%(repo:remote) |The remote associated with the checked out branch,
e.g. `origin/master`.
|%(repo:remote) |The remote name associated with the checked out
branch, e.g. `origin`.
|%(repo:upstream) |The upstream branch associated with the checked out
branch, e.g. `origin/master`.
|%(repo:cdup) |The path to change directory to the repository root,
e.g. `../`
|%(repo:prefix) |The path prefix of the current work directory,
Expand Down
1 change: 1 addition & 0 deletions include/tig/repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef char repo_str[SIZEOF_STR];
_(repo_ref, head) \
_(repo_rev, head_id) \
_(repo_ref, remote) \
_(repo_ref, upstream) \
_(repo_str, cdup) \
_(repo_str, prefix) \
_(repo_str, git_dir) \
Expand Down
6 changes: 2 additions & 4 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,13 +1428,11 @@ set_remote_branch(const char *name, const char *value, size_t valuelen)
string_ncopy(repo.remote, value, valuelen);

} else if (*repo.remote && !strcmp(name, ".merge")) {
size_t from = strlen(repo.remote);

if (!prefixcmp(value, "refs/heads/"))
value += STRING_SIZE("refs/heads/");

if (!string_format_from(repo.remote, &from, "/%s", value))
repo.remote[0] = 0;
if (!string_format(repo.upstream, "%s/%s", repo.remote, value))
repo.upstream[0] = 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/refdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ reload_refs(bool force)
"git", "show-ref", "--head", "--dereference", NULL
};
char ls_remote_cmd[SIZEOF_STR];
struct ref_opt opt = { repo.remote, repo.head, WATCH_NONE };
struct ref_opt opt = { repo.upstream, repo.head, WATCH_NONE };
struct repo_info old_repo = repo;
enum status_code code;
const char *env = getenv("TIG_LS_REMOTE");
Expand Down
8 changes: 6 additions & 2 deletions src/repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ read_repo_info(char *name, size_t namelen, char *value, size_t valuelen, void *d
const char *head = name + STRING_SIZE("refs/heads/");

string_ncopy(repo.head, head, strlen(head) + 1);
add_ref(repo.head_id, name, repo.remote, repo.head);
add_ref(repo.head_id, name, repo.upstream, repo.head);
}
state->argv++;

} else if (!strcmp(arg, REPO_INFO_REMOTE)) {
string_ncopy(repo.remote, name, namelen);
char *sep = strchr(name, '/');

string_ncopy(repo.remote, name, sep - name);
string_ncopy(repo.upstream, name, namelen);
state->argv++;
}

Expand Down Expand Up @@ -117,6 +120,7 @@ load_repo_head(void)
};

memset(repo.remote, 0, sizeof(repo.remote));
memset(repo.upstream, 0, sizeof(repo.upstream));
reload_repo_info(rev_parse_remote_argv);
memset(repo.head, 0, sizeof(repo.head));
memset(repo.head_id, 0, sizeof(repo.head_id));
Expand Down
4 changes: 2 additions & 2 deletions src/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ status_update_onbranch(void)

if (ref && strcmp(ref->name, "HEAD"))
head = ref->name;
} else if (!paths[i][1] && *repo.remote) {
} else if (!paths[i][1] && *repo.upstream) {
if (status_branch_tracking_info(buf, sizeof(buf),
head, repo.remote)) {
head, repo.upstream)) {
tracking_info = buf;
}
}
Expand Down
5 changes: 3 additions & 2 deletions test/status/repo-var-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export LINES=10
steps "
:exec !assert-var '%(repo:head)' == master
:exec !assert-var '%(repo:head-id)' == feeb2dfd5e09e887e4b6c901e7d91a4c85a7831d
:exec !assert-var '%(repo:remote)' == origin/master
:exec !assert-var '%(repo:remote)' == origin
:exec !assert-var '%(repo:upstream)' == origin/master
:exec !assert-var '%(repo:cdup)' == ../
:exec !assert-var '%(repo:prefix)' == repo-two-a/
:exec !assert-var '%(repo:git-dir)' == '$HOME/$work_dir/.git'
Expand All @@ -33,4 +34,4 @@ Untracked files:
[status] Nothing to update 100%
EOF

assert_vars 7
assert_vars 8
5 changes: 4 additions & 1 deletion tigrc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ set pager-autoscroll = no # Scroll the pager view automatically while loading?
#
# User-defined commands can optionally refer to Tig's internal state
# using the following variable names, which are substituted before
# commands are run:
# commands are run (see 'man tigrc' for the full list):
#
# %(head) The current ref ID. Defaults to HEAD
# %(commit) The current commit ID.
Expand All @@ -188,6 +188,9 @@ set pager-autoscroll = no # Scroll the pager view automatically while loading?
# %(cmdlineargs) All other options passed on the command line.
# %(diffargs) The diff options from `diff-options` or `TIG_DIFF_OPTS`
# %(prompt) Prompt for the argument value.
# %(repo:head) The name of the checked out branch.
# %(repo:remote) The remote name associated with the checked out branch.
# %(repo:upstream) The upstream branch associated with the checked out branch.

bind main C ?git cherry-pick %(commit)
bind status C !git commit
Expand Down

0 comments on commit 039abe7

Please sign in to comment.