History

support reflog message prefix (#450)

Sebastian Thiel committed 4 years ago

Commit 6ebbbc11 parent 9a072bd3 files · +10 −6Browse files

Unified · Split

3 files
  1. git-repository/src/remote/connection/fetch/mod.rs +1 −0
  2. git-repository/src/remote/connection/fetch/update_refs/mod.rs +3 −1
  3. git-repository/src/remote/connection/fetch/update_refs/tests.rs +6 −5
git-repository/src/remote/connection/fetch/mod.rs+1−0
@@ -177,6 +177,7 @@ where · 176 unmodified lines
177177
178178 let update_refs = refs::update(
179179 repo,
180+ "fetch",
180181 &self.ref_map.mappings,
181182 con.remote.refspecs(crate::remote::Direction::Fetch),
182183 fetch::DryRun::No,
git-repository/src/remote/connection/fetch/update_refs/mod.rs+3−1
@@ -30,10 +30,12 @@ impl From<update::Mode> for Update { · 29 unmodified lines
3030 /// [`update`][Update] corresponding to the [`fetch::Mapping`] of at the same index.
3131 /// If `dry_run` is true, ref transactions won't actually be applied, but are assumed to work without error so the underlying
3232 /// `repo` is not actually changed.
33+/// `action` is the prefix used for reflog entries, and is typically "fetch".
3334 ///
3435 /// It can be used to produce typical information that one is used to from `git fetch`.
3536 pub(crate) fn update(
3637 repo: &Repository,
38+ action: &str,
3739 mappings: &[fetch::Mapping],
3840 refspecs: &[git_refspec::RefSpec],
3941 dry_run: fetch::DryRun,
@@ -91,7 +93,7 @@ pub(crate) fn update( · 51 unmodified lines
9193 log: LogChange {
9294 mode: RefLog::AndReference,
9395 force_create_reflog: false,
94− message: reflog_message.into(),
96+ message: format!("{}: {}", action, reflog_message).into(),
9597 },
9698 expected: PreviousValue::ExistingMustMatch(Target::Peeled(remote_id.into())),
9799 new: Target::Peeled(remote_id.into()),
git-repository/src/remote/connection/fetch/update_refs/tests.rs+6−5
@@ -93,7 +93,7 @@ mod update { · 92 unmodified lines
9393 // ),
9494 ] {
9595 let (mapping, specs) = mapping_from_spec(spec, &repo);
96− let out = fetch::refs::update(&repo, &mapping, &specs, fetch::DryRun::Yes).unwrap();
96+ let out = fetch::refs::update(&repo, "action", &mapping, &specs, fetch::DryRun::Yes).unwrap();
9797
9898 assert_eq!(
9999 out.updates,
@@ -109,7 +109,8 @@ mod update { · 9 unmodified lines
109109 match &edit.change {
110110 Change::Update { log, .. } => {
111111 assert_eq!(
112− log.message, reflog_message,
112+ log.message,
113+ format!("action: {}", reflog_message),
113114 "reflog messages are specific and we emulate git word for word"
114115 );
115116 }
@@ -137,7 +138,7 @@ mod update { · 21 unmodified lines
137138 ] {
138139 let spec = format!("refs/heads/main:refs/heads/{}", branch);
139140 let (mappings, specs) = mapping_from_spec(&spec, &repo);
140− let out = fetch::refs::update(&repo, &mappings, &specs, fetch::DryRun::Yes)?;
141+ let out = fetch::refs::update(&repo, "action", &mappings, &specs, fetch::DryRun::Yes)?;
141142
142143 assert_eq!(
143144 out.updates,
@@ -158,7 +159,7 @@ mod update { · 14 unmodified lines
158159 fn symbolic_refs_are_never_written() {
159160 let repo = repo("two-origins");
160161 let (mappings, specs) = mapping_from_spec("refs/heads/main:refs/heads/symbolic", &repo);
161− let out = fetch::refs::update(&repo, &mappings, &specs, fetch::DryRun::Yes).unwrap();
162+ let out = fetch::refs::update(&repo, "action", &mappings, &specs, fetch::DryRun::Yes).unwrap();
162163
163164 assert_eq!(
164165 out.updates,
@@ -176,7 +177,7 @@ mod update { · 11 unmodified lines
176177 fn fast_forward_is_not_implemented_yet_but_should_be_denied() {
177178 let repo = repo("two-origins");
178179 let (mappings, specs) = mapping_from_spec("refs/heads/main:refs/remotes/origin/g", &repo);
179− let out = fetch::refs::update(&repo, &mappings, &specs, fetch::DryRun::Yes).unwrap();
180+ let out = fetch::refs::update(&repo, "action", &mappings, &specs, fetch::DryRun::Yes).unwrap();
180181
181182 assert_eq!(
182183 out.updates,